开发者

Access baseUrl() in View Helper?

开发者 https://www.devze.com 2023-02-18 12:28 出处:网络
Simple ZF question: How can the baseUrl() be access开发者_运维百科ed in a View Helper without passing it as an argument?

Simple ZF question:

How can the baseUrl() be access开发者_运维百科ed in a View Helper without passing it as an argument?

Many thanks


You can use Zend_View_Helper_Abstract methods. If your view helper extends Zend_View_Helper_Abstract, then you can use the internal $view member to access the view from which the helper was called. The solution Dickie proposes would fail if your layout view would be different from your action's view. It also introduces new class, that is not needed every time.


You want to access a view helper from within another view helper?

Off the top of my head you will need to get the view object first:

$view = Zend_Layout::getMvcInstance()->getView();

Now you can call baseUrl() (e.g. echo $view->baseUrl();).


You can try this code:

$this->view->baseUrl()
0

精彩评论

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

关注公众号