view->foo =...;)." />
开发者

In Zend-Framewok plugin, how to do somthing simular to $this->view->foo =...;?

开发者 https://www.devze.com 2023-01-09 15:34 出处:网络
i wrote a small plugin, so i will be able to get the name of the controller in each view. but idk how to \"pass\" a parameter to the view (do sumth like $this->view->foo =...;).

i wrote a small plugin, so i will be able to get the name of the controller in each view. but idk how to "pass" a parameter to the view (do sumth like $this->view->foo =...;).

class Zend_Extension_Controller_Plugin_GetControllerName extends Zend_Controller_Plugin_Abstract
{

    public function __construct()
    {

    }

    public function preDispatch(Zend_Controller_Req开发者_开发问答uest_Abstract $request)
    {
        $this->view->controllerName = $request->getControllerName();
    }
}

what can i write instead of $this->view->controllerName so it will work?


Try this:

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


You can use the helper broker to get an instance of the view. Something like this should work:

Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer')->view->foo = 'bar';


Take this example as basis:

class Plugin_Sidebar extends Zend_Controller_Plugin_Abstract {

    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {
        if($request->getModuleName() == 'admin')
        {
            return;
        }

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


        $Categories = new Model_DbTable_Categories();
        $view->menuItens = $Categories->getMenu();

    }
}
0

精彩评论

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

关注公众号