<?php /* CONFIG --------------------------------------------------------------------------------------- */ $config = array('sess_cookie' => 'micro'); /* ROUTING -------------------------------------------------------------------------------------- */ // it's my personal naming convention to prefix routing callbacks with _r function _r_generic_route($matches) { $result = array($matches['controller'], isset($matches['action']) ? $matches['action'] : 'index'); // The third element (parameters), if it exists, must always be an array. if (isset($matches['glob'])) { if (strpos($matches['glob'], '/') === false) { // singular parameter $result[] = array(urldecode($matches['glob'])); } else { // multiple parameters $result[] = array_map('urldecode', explode('/', $matches['glob'])); } } return $result; } // Route priority is in the reverse of the order it is registered; // that is, the last route is tested first Micro::add_route('', array('welcome', 'index'), 'match'); Micro::add_route('#^(?P<controller>[a-z][-_a-z]*)(?:/(?P<action>[a-z][-_a-z]*)/?(?P<glob>[^\\#]*))?$#i', '_r_generic_route');
$class = ucfirst($controller); $file = MICRO_PATH . "/application/controllers/{$controller}.php"; if (is_file($file) && class_exists($class) == false) { include $file; if (!method_exists($class, $action)) { throw new RoutingException("404: Unknown Action", $info); } $control = new $class(); // Pass the params as an array so we don't hit an "expected parameter" error from the // method we're calling if we use call_user_func_array(). $control->{$action}($params); return $control; } throw new RoutingException("404: Unknown Controller", $info); } /**** MAGIC STUFF ****/ function __construct() { // $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; // Micro::$missing_route = array(Micro::$default_controller, 'missing', array(REQUEST_URI, $referrer)); } } include MICRO_PATH . '/application/includes/config.php'; include MICRO_PATH . '/application/includes/helpers.php'; try { $micro = new Micro(); $controller = $micro->dispatch(Micro::handle_route(REQUEST_URI)); } catch (Exception $e) { // a very rudimentary error page... echo $e; }
$view_folder = APPPATH . $view_folder; } elseif (!is_dir(APPPATH . 'views' . DIRECTORY_SEPARATOR)) { header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF; exit(3); // EXIT_CONFIG } else { $view_folder = APPPATH . 'views'; } } if (($_temp = realpath($view_folder)) !== FALSE) { $view_folder = $_temp . DIRECTORY_SEPARATOR; } else { $view_folder = rtrim($view_folder, '/\\') . DIRECTORY_SEPARATOR; } define('VIEWPATH', $view_folder); // change the following paths if necessary $micro = $system_path . 'micro.php'; //$config = $system_path . '/protected/config/main.php'; require_once $micro; Micro::init(); /* * -------------------------------------------------------------------- * LOAD THE BOOTSTRAP FILE * -------------------------------------------------------------------- * * And away we go... */ require_once BASEPATH . 'core/CodeIgniter.php'; /* End of file index.php */ /* Location: ./index.php */