Example #1
0
 function executeAction($controller, $params)
 {
     // Where to find what
     $this->paths = array(BASEAPP_PATH, APP_PATH);
     $controller_class = Inflector::camelize($controller);
     $controller_class_name = $controller_class . 'Controller';
     // Is it a component
     if (is_dir(APP_PATH . 'components/' . $controller)) {
         $this->paths[] = APP_PATH . 'components/' . $controller . '/';
     }
     uses($controller_class, B_CONTROLLER);
     // get a instance of that controller
     if (class_exists($controller_class_name)) {
         $this->Controller = new $controller_class_name();
     } else {
         //page_not_found();
     }
     if (!is_subclass_of($this->Controller, 'Controller')) {
         die("Class '{$controller_class_name}' does not extends Controller class!");
     }
     // Setup database is required
     if (Configure::read('dbName')) {
         // connect to db
         include CORE_PATH . 'libraries/adodb/adodb.inc.php';
         extract(Configure::readConfig());
         $this->Controller->db = ADONewConnection($dbType);
         # eg 'mysql' or 'postgres'
         if (!$this->Controller->db->Connect($dbHostname, $dbUsername, $dbPassword, $dbName)) {
             throw new Exception('Could not connect to database');
         }
     }
     // Various controller globals
     $this->Controller->base = getInstance();
     $this->Controller->Session = new Session();
     $this->Controller->Cookie = new Cookie();
     $this->Controller->data = $this->Controller->getData();
     // load the helpers,libraries and models
     if (isset($this->Controller->helpers)) {
         uses($this->Controller->helpers, B_HELPER);
     }
     if (isset($this->Controller->libraries)) {
         uses($this->Controller->libraries, B_LIBRARY);
     }
     if (isset($this->Controller->uses)) {
         uses($this->Controller->uses, B_MODEL);
     }
     //beforeFilter
     if (method_exists($this->Controller, 'beforeFilter')) {
         call_user_func(array($this->Controller, 'beforeFilter'));
     }
     // load the helpers,libraries and models if any changes made by before filter
     if (isset($this->Controller->helpers)) {
         uses($this->Controller->helpers, B_HELPER);
     }
     if (isset($this->Controller->libraries)) {
         uses($this->Controller->libraries, B_LIBRARY);
     }
     if (isset($this->Controller->uses)) {
         uses($this->Controller->uses, B_MODEL);
     }
     $this->Controller->execute($this->actionName, $this->params);
 }