Create controller plugin
Posted on July 22, 2013
Create an custom controller plugin
Plugin code
namespace ExampleControllerPlugin;
use ZendMvcControllerPluginAbstractPlugin;
class DoStuff extends AbstractPlugin{
protected $entityManager;
public function __invoke(){
//Do your stuff
}
//Getters and setters
public function setEntityManager($entitymanager){
return $this->entityManager = $entitymanager;
}
}
Module.php setup
public function getControllerPluginConfig()
{
return array(
'factories' => array(
'doStuff' => function ($sm) {
$serviceLocator = $sm->getServiceLocator();
$controllerPlugin = new ControllerPluginDoStuff();
$controllerPlugin->setEntityManager($serviceLocator->get('DoctrineORMEntityManager'));
return $controllerPlugin;
},
),
);
}