<?php // Twig require_once './vendor/twig/twig/lib/Twig/Autoloader.php'; Twig_Autoloader::register(); // Autoloader spl_autoload_register(function ($class) { $root = '.'; // root is current file $class_file = str_replace('\\', '/', $class); $file = "{$root}/{$class_file}.php"; if (is_readable($file)) { require $file; } }); // Error and Exception Handling error_reporting(E_ALL); set_error_handler('Core\\Error::errorHandler'); set_exception_handler('Core\\Error::exceptionHandler'); /** * Routing */ $router = new Core\Router(); $router->add('', ['controller' => 'Home', 'action' => 'index']); $router->add('authenticate', ['controller' => 'Authenticate', 'action' => 'index']); $router->add('diary', ['controller' => 'Diary', 'action' => 'index']); $router->add('{controller}/{action}'); $router->add('admin/{controller}/{action}', ['namespace' => 'Admin']); $router->dispatch($_SERVER['QUERY_STRING']);
<?php /** * Index page * * Loads the libraries and calls the router to handle the request * * @package Core */ /* Autoload libraries */ require_once 'vendor/autoload.php'; /* Dispatch the request */ Core\Router::dispatch();
<?php /** * Composer autoloader * */ require_once '../vendor/autoload.php'; /** * Error and Exception handling * */ error_reporting(E_ALL); set_error_handler('Core\\Error::errorHandler'); set_exception_handler('Core\\Error::exceptionHandler'); if (session_status() == PHP_SESSION_NONE) { session_start(); } $router = new \Core\Router(); /** * Add the Route * */ $router->add('', ['controller' => 'HomeController', 'action' => 'index']); $router->add('home', ['controller' => 'HomeController', 'action' => 'index']); $router->add('home/fileupload', ['controller' => 'HomeController', 'action' => 'fileUpload']); $router->add('contact', ['controller' => 'ContactController', 'action' => 'index']); $router->add('admin/users/{id:\\d+}/index', ['controller' => 'UsersController', 'action' => 'index', 'namespace' => 'Admin']); //$router->add('{controller}/{id:\d+}/{action}'); $url = $_SERVER['QUERY_STRING']; $router->dispatch($url);
*/ define('ROOT_PATH', realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR); //项目根目录 require_once 'config/init.conf.php'; require_once CORE_PATH . 'Loader.php'; //捕获错误信息 function getLastErr() { $errInfo = error_get_last(); if (null != $errInfo) { $fileName = ROOT_PATH . 'logs' . DIRECTORY_SEPARATOR . 'error.log'; $errStr = date('Y-m-d H:i:s'); foreach ($errInfo as $key => $value) { $errStr .= $key . '=' . $value . ','; } file_put_contents($fileName, $errStr, FILE_APPEND); } } register_shutdown_function('getLastErr'); registerAutoLoad(); try { $routerObj = new Core\Router(); $routerObj->dispatch(); } catch (Exception $exc) { $logObj = new Core\Log(EXCEPTION_LOG_FILE, false, EXCEPTION_LOG_PATH); $logObj->exceptionLog(array('code' => $exc->getCode(), 'msg' => $exc->getMessage(), 'file' => $exc->getFile(), 'trace' => $exc->getTraceAsString())); $logObj->closeFile(); if ('dev' == ENV) { Core\CommonFunction::show_exception($exc); } }