在Zend Framework2中,我记得有一个插件模块A插件模块B。
如果你从控制器调用这个插件,它在任何地方都可以工作,但是我需要在另一个插件中调用一个插件。
我该怎么做呢?
发布于 2013-06-26 00:30:47
基本上,您必须向PluginB中注入PluginA。即:
$pluginA = new PluginA();
$pluginB = new PluginB($pluginA);
echo $pluginB("Hello World");
class PluginB {
protected $pluginA;
public function __construct(PluginA $pluginA) {
$this->pluginA = $pluginA;
}
public function __invoke($arg) {
$step1 = $this->doSomething($arg);
return $this->pluginA->doSomeOtherPluginAThing($step1);
}
}
最终,您的解决方案看起来会有点不同,您将通过ServiceManager工厂进行注入
发布于 2013-06-26 00:41:30
你可以从你的插件内部访问控制器:
$this->getController()->anotherPlugin();
发布于 2013-07-02 05:26:45
尝试从控制器插件管理器加载插件。
PluginB
$pluginA = $this->serviceLocator->get('ControllerPluginManager')->get('pluginA');
// Invoke plugin as normal
$pluginA(params);
https://stackoverflow.com/questions/17301223
复制相似问题