Jan Walraven
DevOps



Categories:
  • Arduino (2)
  • CSS (3)
  • Docker (10)
  • ESXi (1)
  • Git (4)
  • Google Cloud (2)
  • Javascript (6)
  • Linux (31)
  • Mac (6)
  • Magento (4)
  • Mysql (13)
  • 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;
    			},
    		),
    	);
    }