Php Zend框架-插件
对于控制器中的一个操作,启动插件的最佳方式是什么 补编: 这是一段代码,我想在IndexController中运行这个插件进行testActionPhp Zend框架-插件,php,zend-framework,Php,Zend Framework,对于控制器中的一个操作,启动插件的最佳方式是什么 补编: 这是一段代码,我想在IndexController中运行这个插件进行testAction class MyApp_Plugin_MyPlugin extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { print 'hello worl
class MyApp_Plugin_MyPlugin extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
print 'hello world';
}
}
我希望这段代码将对您有所帮助Zoot
致以最诚挚的问候您可以直接调用插件
public function someAction()
{
// The action in the controller you want the plugin to run
$p = new Application_Plugin_Something();
$p->doSomething();
}
或者在引导中注册它,让插件检查执行它的内容
class Application_Plugin_Example extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
if ($module != 'default' && $controller != 'TheController' && $action != 'TheAction') {
return;
}
// plugin code here...
}
}
// in bootstrap
Zend_Controller_Front::getInstance()
->registerPlugin(
new Application_Plugin_Example()
);
在插件代码中,只需将“default”替换为正确的模块,“TheController”和“TheAction”替换为您希望插件运行的控制器和操作。此处的一些代码可能会有所帮助,以及您试图完成的任务的描述。