Search code examples
phpzend-framework2zend-view

ZF2: ViewHelper doesn't return value


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 :)


Solution

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

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

    Works.