Создаём файл плагина module/MyModule/src/MyModule/Controller/Plugin/MyFirstPlugin.php
[cc lang=»php»]
< ?php
namespace MyModule\Controller\Plugin;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
class MyFirstPlugin extends AbstractPlugin
{
public function doSomething() {
// ...
}
}
[/cc]
Далее в module/MyModule/config/module.config.php
[cc lang=»php»]
< ?php
return array(
// ... your configuration
'controller_plugins' => array(
‘invokables’ => array(
‘MyFirstPlugin’ => ‘MyModule\Controller\Plugin\MyFirstPlugin’,
)
),
// …
);
[/cc]
Теперь в файле контролера module/MyModule/src/MyModule/Controller/IndexController.php вызываем плагин
[cc lang=»php»]
< ?php
namespace MyModule\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class IndexController extends AbstractActionController {
public function indexAction() {
$plugin = $this->MyFirstPlugin();
$plugin->doSomething();
return new ViewModel();
}
}
[/cc]