duanhan5388 2014-09-01 07:24
浏览 29
已采纳

ZF2:ViewHelper不返回值

I cannot find any solution nor even a question about this. I think its because it must be something completely obvious or this is an error nobody ever got.

Cause, its not an error! Im not getting a error message, nothing in my logs, everything works fine. Well, atleast, thats what all the technics think. But I want a return from my Helper, and I want it to be echo'd. Problem here, not getting any result. Also a var dump, print r of exit don't show any return.

My ViewHelper:

<?php

namespace Tijdmachine\View\Helper;
use Zend\View\Helper\AbstractHelper;

class Timehelper extends AbstractHelper
{
    public function __invoke()
    {
        return 'hi';
        //return date('H:i:s');
    }
}

Partial view:

 For some reason, its is: <?=$this->time_helper?>

I declared it in module.config.php:

'view_helpers' => array(
        'invokables'=> array(
            'time_helper' => __NAMESPACE__.'\View\Helper\Timehelper'  
        )
    ),

I tried putting a use in my controller, but ofc that doens't work and isn't required.

I'm quite curious about my mistake :)

  • 写回答

1条回答 默认 最新

  • douchensou6495 2014-09-01 08:12
    关注

    I found the answer, the view object is an object... So,

    echo $this->time_helper(); //note the ().
    

    Works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页