Studyon Minte9.com
ZF 1.0




Broker



The controller architecture includes a plugin system that allows user code to be called when certain events occur in the controller process lifetime.

The event methods are defined in the abstract class Zend_Controller_Plugin_Abstract, from which user plugin classes inherit.

#index.php
<?php
...
$frontController->registerPlugin(new Application_Plugin_My();


#Aplication/Plugin/My.php
<?php
require_once "Zend/Controller/Plugin/Abstract.php";
class Application_Plugin_My extends Zend_Controller_Plugin_Abstract {
	
	public function __construct() {}
	
	public function routeStartup(Zend_Controller_Request_Abstract $request) {
		$this->getResponse()->appendBody("<p> routeStartup() <p>");
	}

	public function routeShutdown(Zend_Controller_Request_Abstract $request) {
		$this->getResponse()->appendBody("<p> routeShutdown() <p>");
	}

	public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
		$this->getResponse()->appendBody("<p> dispatchLoopStartup() <p>");
	}

	public function preDispatch(Zend_Controller_Request_Abstract $request) {
		$this->getResponse()->appendBody("<p> preDispatch() <p>");
	}

	public function postDispatch(Zend_Controller_Request_Abstract $request) {
		$this->getResponse()->appendBody("<p> postDispatch() <p>");
	}

}

#controller
<?php
	...
	public function indexAction() {
		
		echo '<p> Index action </p>';
		
		$this->view->message = "Hello world";
	}

#view
<?php echo $this->message; ?>


#http://zfsite/ (will display)

	routeStartup()
	routeShutdown()
	dispatchLoopStartup()
	preDispatch()

	Hello world

	Index action

	postDispatch() 


http://framework.zend.com/manual/1.11/en/zend.controller.plugins.html
http://devzone.zend.com/article/3372