注入控制器属性我写了需要设置,因此目前正被指派的控制器上的属性插件。例如,如果我的插件是:Zend框架:如何从Zend_Controller_Plugin
class Application_Plugin_Foo extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
// Get an instance of the current controller and inject the $foo property
// ???->foo = 'foo';
}
}
我希望能够做到这一点:
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$this->view->foo = $this->foo;
}
}
}
任何帮助,不胜感激!
似乎对ZF动作控制器的*简单的资源喷油器*链接的内容被复制到@ DavidW的答案,但我强烈建议你阅读原始页面上的整个讨论。还有很多有用的评论。 – chelmertz 2010-10-02 09:24:37
在发布此问题之前,我开始采用getParam()方法。我甚至认为“扩展一个基本控制器”的方式,但也发现在这里有许多不值得讨论的缺陷。使用动作助手似乎是做我想做的事情的正确方式,但在阅读了你提到的文章之后,我改变了主意,并将采用马修所描述的“注入依赖”方式。看起来与一群程序员一起工作最有效的方法。 – Julian 2010-10-03 18:55:49
@ Julian我同意你的观点,但如果没有正确记录,可能很难找到所有这些依赖关系来自哪里。总而言之,这似乎是一个坚实的方法! – chelmertz 2010-10-03 21:52:07