ZF-7907: Current view helper strategy does not work with namespaced classes
Description
This class cannot be used as a view helper since the main method is treated as a constructor. The possibility of using a direct() method should be provided.
namespace NakedPhp\Mvc\View\Helper; use NakedPhp\Metadata\NakedObject; class DisplayObject extends \Zend_View_Helper_Abstract { public function __construct() { } public function displayObject() { return ''; } }
Comments
Posted by Giorgio Sironi (giorgiosironi) on 2009-09-21T05:57:39.000+0000
Workaround: use a __call method instead.
Posted by Raphael Dehousse (thymus) on 2010-07-15T00:58:46.000+0000
Hello,
For this, I overload Zend_View_Abstract to add in the __call method
Posted by Raphael Dehousse (thymus) on 2010-07-15T01:53:00.000+0000
Error in my previous comment because Zend_View_Helper_Abstract has an empty "direct" method
is working for me in 1.10.6 :)
Posted by Steven Rosato (ratius) on 2010-09-03T06:35:31.000+0000
As far as I am concerned, implementing the direct() function with required arguments will fail with a fatal error such as:
I have used Raph's overloading strategy, but with the function name 'helper' instead, though this would still forbid anyone to have a Helper named Helper, but that would be kind of unintuitive.
Posted by Matthew Weier O'Phinney (matthew) on 2010-09-03T06:50:41.000+0000
We've run into this in ZF2 already. The solution is that all arguments must be optional, and then you perform checks for required arguments as the first part of the body.
That said, we're likely moving to a slightly different paradigm for ZF2 anyways: you will retrieve your helper object from a broker, and simply call the methods you want:
This is slightly more verbose, but also (a) faster (__call(), since it often uses call_user_func_array() internally, is around 6X slower than directly calling a method), (b) more explicit, and thus easier to understand (many newcomers do not understand where to find methods like "form()" and "headTitle()" -- the helper system is hard to grasp immediately), and (c) more portable (we can build the broker into other templating solutions easily).
I'm not sure if we can easily accommodate namespaced helpers in ZF1, to be honest.