Getting View Object from within a Zend Controller plugin

自作多情 提交于 2019-12-01 08:15:11

I found your post while searching for the same thing. Based on this thread, there are two simple ways to accomplish it.

One: If your view is initialized during bootstrap (resources.view[] = is in your application.ini), you can simply call this:

$view = Zend_Controller_Front::getInstance()
        ->getParam('bootstrap')
        ->getResource('view');

Two: If your view is not initialized during bootstrap:

$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
if (null === $viewRenderer->view) {
    $viewRenderer->initView();
}
$view = $viewRenderer->view;

I believe it's the wrong way to do it. The FlashMessenger is to have little notifications from one request to the next; available in the view.

Thus, the flashmessenger is already a controller action helper (for the above purpose) why do you want to build another helper on top of that? :)

So, your problem is actually getting the messages in the view. For that, there is already a view helper. From noumenal. It's awesome.

If you are just looking to get this functionality in all of your controllers, you can just extend the Zend_Controller_Action and make a new class containing your post dispatch code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!