开发者

Zend-Framework View Helper - Is it specific view related?

When we create a view helper, on a Zend application, will that helper be available for ALL the view开发者_如何学Cs or, should we somehow tell that THAT view helper is available to a specific view? What if, on the view folder "something", we have more then one file ? Any of those files can call it?

Thanks a lot, MEM


When you call a view helper, the framework will look within the paths defined via $view->addHelperPath(). Typically, such a call will include a pseudo-namespace as well as a path:

$view->addHelperPath('My/View/Helper', 'My_View_Helper_');

Then when you call a view helper in a layout or a view script:

<?php echo $this->someHelper() ?>

The framework will do a LIFO search, appending the prefixes (in the above case: 'My_View_Helper_') to the classname 'SomeHelper' and then attempting to load the file defined by the addHelperPath() mapping.

In the default setup, the framework pre-loads the Zend view helpers by calling:

$view->addHelperPath('Zend/View/Helper', 'Zend_View_Helper_');

which is why you can use all the Zend-provided view helpers right out of the box.

Since all this processing is independent of which view script is making the call, it will work in any view script. [There are actually some issues associated to calling view helpers defined in other modules, but that's a separate issue.]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜