我有class Plugin_Magazine extends Zend_Controller_Action
在一些视图中,我需要从它调用static function test()
。
in view:
$class_name = 'Plugin_'.$plugin;
$class_name::test();
作为结果,我有
可捕获致命错误:参数1传递给Zend_Controller_Action::__construct()必须是Zend_Controller_Request_Abstract, none given
但是,如果我创建class Plugin_Magazine
w'o 扩展所有工作正常。
的问题是:我能不能做我需要的事情或者干脆忘记继承?
你需要传递一个Request对象给Action类的构造函数
当你这样做的时候:
$pm = new Plugin_Magazine();
但是你需要传递请求对象:
$pm = new Plugin_Magazine($this->getRequest());
对于这个调用:
$class_name = 'Plugin_'.$plugin;
$class_name::test();
为什么在Action中需要静态函数?这似乎是不对的,如果它是存在于Action中的可重用逻辑,那么它应该被移动到其他可以更容易使用的地方,例如到模型中。