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.

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

报告相同问题?