Issues

ZF-9393: Zend_Dojo_View_Helper_Dojo should have String representation method "toString"

Issue Type: Improvement Created: 2010-03-10T10:19:12.000+0000 Last Updated: 2012-11-20T21:37:51.000+0000 Status: Reopened Fix version(s): Reporter: bullfrogblues (gerardroche) Assignee: None Tags: - Zend_Dojo

Related issues: Attachments:

Description

View helpers like headMeta, headTitle, headLink, etc have a toString method string representation method, the dojo helper doesn't, it should.

e.g.

echo $this->getHelper('headMeta'); echo $this->getHelper('headMeta')->toString();

will both work.

echo $this->getHelper('dojo');

doesn't, it fails "Catchable fatal error: Object of class Zend_Dojo_View_Helper_Dojo could not be converted to string"

And

echo $this->getHelper('dojo')->toString();

won't work because there is no toString method "Zend_Dojo_View_Exception: Invalid method "toString" called on dojo view helper"

Comments

Posted by Matthew Weier O'Phinney (matthew) on 2010-03-10T10:46:49.000+0000

Why are you using getHelper()?

The intended use of the Dojo view helper is using Zend_View as a proxy:

<pre class="highlight">
echo $this->dojo();

This ensures that the appropriate method (Zend_Dojo_View_Helper_Dojo::dojo()) is called, and that the return value from it is used. If you look at that method, it actually returns an instance of Zend_Dojo_View_Helper_Dojo_Container, which contains toString() and __toString(), and which can be echoed both directly or by calling the toString() method.

(The reason for this design is that the container object is placed in a registry, which ensures that it exists across multiple instances of Zend_View -- particularly useful when using partials.)

Posted by bullfrogblues (gerardroche) on 2010-03-11T01:45:46.000+0000

Zend_Dojo_View_Helper_Dojo_Container contains a "__toString" method but it does NOT contain a "toString" method, ZF 1.10.2.

echo $this->getHelper('dojo')->toString() is more instructive and concrete about what is actually happening than echo $this->dojo().

  • though I'm sure it might be trivial it's one less "call_user_func_array" call & 1 less call to a method of the helper itself (i.e. the helper named method, e.g. in headMeta it's headMeta, (needless if you're not passing in any parameters).

If getHelper is not intended to be used this way it should be protected or not exist at all, I don't see any other use-case for it.

"This ensures that the appropriate method (Zend_Dojo_View_Helper_Dojo::dojo()) is called, and that the return value from it is used ... (The reason for this design is that the container object is placed in a registry, which ensures that it exists across multiple instances of Zend_View - particularly useful when using partials.)"

View heleprs headMeta, headTitle, headLinks, etc are no different yet $this->getHelper('headMeta')->toString() works.

Posted by bullfrogblues (gerardroche) on 2010-03-11T01:48:24.000+0000

that was:

echo $this->getHelper('dojo')>toString()

is more instructive and concrete about what is actually happening than

echo $this>dojo().

That wasn't supposed to be crossed out, but I'm not able to edit that comment.

Posted by Matthew Weier O'Phinney (matthew) on 2010-03-11T04:56:58.000+0000

getHelper() is primarily intended for retrieving the helper in order to inject dependencies; in most cases, you utilize helpers by calling them as methods of the view object.

I'm re-opening this as a feature request.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts