Example #1
0
 public function _init()
 {
     /*
      * Auto bind the model
      * 
      * If the controller -class has defined the variable "bindModelName", then we use the name in that variable,
      * otherwise use the name of controller
      * 
      * Example:
      * 
      * class FoobarController extends Controller {
      * 		var $bindModelName = "users";
      * }
      * 
      * This would cause the controller to automatically bind to model "users" instead of "foobar"
      * 
      */
     $this->autoBindModel = Model::getModelIfExists(empty($this->bindModelName) ? $this->controllerName : $this->bindModelName);
     /*
      * Add the AUTOLOAD -models to this Controller. Autoload -models are models
      * which are always available via $this->Modelname in all controllers
      */
     if (property_exists('AppConfiguration', 'AUTOLOAD_MODELS')) {
         foreach (AppConfiguration::$AUTOLOAD_MODELS as $model) {
             $casedName = Inflector::camelize($model);
             $this->{$casedName} = Model::getModel($model);
         }
     }
 }
Example #2
0
/**
 * Define an autoload method
 */
function __autoload($classname)
{
    if (preg_match("#Model\$#", $classname)) {
        Model::getModelIfExists(str_replace('Model', '', $classname));
    }
}