Jan Walraven
DevOps



Menu
Categories:
Posted on

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

}