Studyon Minte9.com
ZF 1.0




Register



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

In order to write a plugin class, simply include and extend the abstract class Zend_Controller_Plugin_Abstract.
None of the methods of Zend_Controller_Plugin_Abstract are abstract, and this means that plugin classes are not forced to implement any of the available event methods listed above. Plugin writers may implement only those methods required by their particular needs. 

Almost every application uses a database connection and acl module. Why doing this in the bootstrap and to mantain many lines of code there, instead of making it clear and mantainable. Of course you can have all these lines of code in your bootstrap, but you know for serious applications that recently will become an obstacle. That?s why Zend Framework allows you to use Front_Controller plugin.


zfsite/html/index.php
-------------------------------------------
<?php 
	...
	// plugins
	$frontController = Zend_Controller_Front::getInstance();
	$frontController->registerPlugin(new Application_Plugin_DBConnection());


zfsite/Application/Plugin/DBConnection.php
--------------------------------------------
<?php
require_once "Zend/Controller/Plugin/Abstract.php";

class Application_Plugin_DBConnection extends Zend_Controller_Plugin_Abstract {
	
	public function __construct() {
		$this->initDB();
	}

	public function initDB() {

		// db connection
		$db = Zend_Db::factory(_DB_ADAPTER, array(
		...
	}
}


http://framework.zend.com/manual/en/zend.controller.plugins.html
http://www.stoimen.com/blog/2009/06/19/zend-framework-quick-tutorial-part-3-front-controller-plugins/