在Zend-Framework插件中,如何做类似于$ 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_Request_Abstract $request)
    {
        $this->view->controllerName = $request->getControllerName();
    }
}

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

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';

Try this:

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

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();

    }
}