/** * Load controller * * @param array $cmv array('controller' => '', 'method' => '', 'vars' => array()) */ private function loadController($cmv) { //if we have nothing to do, then quit if (empty($cmv) or empty($cmv['controller']) or empty($cmv['method'])) { trigger_error('Not call controller->method', E_USER_ERROR); exit; } if (!is_array($cmv['controller'])) { $cmv['controller'] = array($cmv['controller']); } self::$controller = implode("\\", $cmv['controller']); self::$method = $cmv['method']; $this->view->setView(self::$controller . DS . self::$method); //add controllers folder to begin and uppercase first letter class name array_unshift($cmv['controller'], 'controllers'); end($cmv['controller']); $cmv['controller'][key($cmv['controller'])] = ucfirst($cmv['controller'][key($cmv['controller'])]); $cmv['controller'] = "\\" . implode("\\", $cmv['controller']); $controller = new $cmv['controller']($this->config, $this->router, $this->view); if (method_exists($controller, 'beforeMethod')) { Debug::timer('beforeMethod'); $controller->beforeMethod(); Debug::timer('beforeMethod'); } if (is_callable(array($controller, $cmv['method']), true)) { Debug::timer('Controller logic'); call_user_func_array(array($controller, $cmv['method']), $cmv['vars']); Debug::timer('Controller logic'); } if (method_exists($controller, 'afterMethod')) { Debug::timer('afterMethod'); $controller->afterMethod(); Debug::timer('afterMethod'); } }