Call Plugin in other Plugin ZF2

空扰寡人 提交于 2020-01-04 07:55:15

问题


in Zend Framework 2 as I can recall a plugin module A plug-in module B.

If you recall the plugin from the controller, it works everywhere, but I need to call a plugin in another plugin.

How can I do?


回答1:


You basically have to inject PluginA into PluginB. I.e:

$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);
    } 
}

Ultimately your Solution would look a little different and you'd do the injection via ServiceManager Factories




回答2:


You can access controller from inside your plugin:

$this->getController()->anotherPlugin();



回答3:


Try loading the plugin from the Controller Plugin Manager.

PluginB

$pluginA = $this->serviceLocator->get('ControllerPluginManager')->get('pluginA');
// Invoke plugin as normal
$pluginA(params);


来源:https://stackoverflow.com/questions/17301223/call-plugin-in-other-plugin-zf2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!