/** * View Loader * * EN: Load the "view" file. * ID: Berfungsi untuk me-load file "view". * * @access public * @param string * @param array * @return void * @since Version 0.2.1 */ public function __call($file, $data = null) { $file = explode('_', $file); if (!isset($data[0])) { $data[0] = array(); } if ($file[0] != 'view') { Library_error::_404(); } $file = array_slice($file, 1); $file_path = APPLICATION . 'view/'; if (count($file) == 1) { $this->output($file[0], $data[0]); } else { // EN: First, construct the folder location foreach ($file as $key => $val) { $file_path .= $val . '/'; if (is_dir($file_path)) { $next_key = $key + 1; if (!is_dir($file_path . $file[$next_key])) { $arr_file_key = $next_key; break; } } } if (!isset($arr_file_key)) { $arr_file_key = 0; $file_path = APPLICATION . 'view/'; } // EN: Second, construct the file name $arr_file_name = array_splice($file, $arr_file_key, count($file)); $folder_name = implode('/', $file); $file_name = implode('_', $arr_file_name); $file_path = ltrim($folder_name . '/' . $file_name, '/'); $this->output($file_path, $data[0]); } }
/** * Initiate contoller within contoller * * @return void * @param string $controller Controller's name * @param array $params The parameters for it controller * @param string $alias_method a method name for alias call */ public static function sub_controller($class_file, $params = array(), $alias_method = false) { $requsts = array(); if (!empty($params[1])) { $requsts = array_slice($params, 1); } if (!($class_file = self::is_controller_exists($class_file))) { Library_error::_404(); } include_once $class_file; $controller = str_replace('.php', '', end(explode('/', $class_file))); $controller = 'Controller_' . $controller; $controller = new $controller(); // Initiate Default Method $method = 'index'; if (!empty($params[0])) { $method = $params[0]; } if (!method_exists($controller, $method)) { if (!$alias_method) { Library_error::_404(); } $requsts = $requsts ? array_merge(array($method), $requsts) : array($method); $method = $alias_method; } call_user_func_array(array($controller, $method), $requsts); }