Studyon Minte9.com
ZF 1.0




Model broker



// controller
<?php
	private $_modelBroker = array(); 

	public function __get($var) {
		if ( strstr($var, 'Model')) {
			$modelKey = substr($var, 0, -5);
			if ( in_array( $modelKey, array_keys($this->_modelBroker)) ) {
				return $this->_modelBroker[$modelKey];
			} else {    
				eval ('$model = new Models_' . ucfirst($modelKey) . '();');
				$this->_modelBroker[$modelKey] = $model;
				return $model;
			}
		}
	} 


No need to instantiate model in controller 

instead of:
	$userModel = new Models_User(); 
	$userModel->do();
just:
	$this->userModel->do();


http://www.minte9.com/kb/get-magic-method-php-programming-advanced-i2615
http://www.minte9.com/kb/php-magic-methods-php-programming-advanced-i3983