function auto_load_model($model_name) { $file = APP_PATH . '/app/models/' . App::to_underscore(str_replace('_', '/', $model_name)) . '.php'; if (file_exists($file)) { require $file; } }
/** * Proccess controller, action and show response * * @param obj $request * @return void */ public function proccess_controller($request) { $core_controllers = array('RequestError' => CORE_PATH . '/class/'); $controller_path = isset($core_controllers[$request->controller_name]) ? $core_controllers[$request->controller_name] : APP_PATH . '/app/controllers/'; $real_class_name = $request->controller_name . 'Controller'; // ex. HomeController || Admin_HomeController require_once $controller_path . App::to_underscore(str_replace('_', '/', $real_class_name)) . '.php'; $controller = new $real_class_name($this, $request, new Response(), new View()); $response = $controller->process(); $this->fire_event('on_complete'); echo $response; }
/** * Proccess controller * * @return object Response */ public function process() { $this->response->charset = $this->app->config['charset']; // Protect from CSRF if ($this->csrf_protection && $this->app->block_request($this->request)) { $this->request->params['_token'] = REQUEST_TOKEN; $this->render_error(401); } // Set default view to render $action_name = $this->request->action_name; $this->view->params = $this->params; $this->render(App::to_underscore(str_replace('_', '/', $this->request->controller_name)) . '/' . $this->request->action_name); // Get AppController variables $app_controller_vars = get_class_vars('AppController'); // Merge AppController hooks with active controller $this->before_action = array_merge($app_controller_vars['before_action'], $this->before_action); $this->after_action = array_merge($app_controller_vars['after_action'], $this->after_action); // Execute before_actions $this->execute_methods($this->before_action); // Execute main action $this->{$action_name}(); // Execute after_actions $this->execute_methods($this->after_action); // Add helpers in controller to App instace $this->app->add_helpers(array_merge($app_controller_vars['helpers'], $this->helpers)); // Set response body $this->response->body = $this->view->process($this->layout, $this->content_for_layout, $this->app->helpers, $this->request); // Return a Response object return $this->response; }