Jan Walraven
DevOps



Categories:
  • Arduino (2)
  • CSS (3)
  • Docker (11)
  • ESXi (1)
  • Git (4)
  • Google Cloud (3)
  • Javascript (6)
  • Kubernetes (4)
  • Linux (36)
  • Mac (7)
  • Magento (4)
  • Mysql (14)
  • PHP (9)
  • Zend framework 2 (9)
  • 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;
    			},
    		),
    	);
    }