Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -> .htaccess
- AddDefaultCharset UTF-8
- RewriteEngine ON
- ErrorDocument 401 /error/401
- ErrorDocument 403 /error/403
- ErrorDocument 404 /error/404
- ErrorDocument 500 /error/500
- RewriteRule ^(.*)$ index.php?url=$1 [QSA]
- -> index.php
- <?php
- if (session_status() == PHP_SESSION_NONE) {
- session_start();
- }
- spl_autoload_register(
- function($className)
- {
- $classPathCore = 'modules/core/'.lcfirst($className).'.inc.php';
- if(file_exists($classPathCore)) {
- require($classPathCore);
- } else {
- $classPathParts = explode('_', $className);
- $classPath = 'modules/'.lcfirst($classPathParts[0]).'/'.
- lcfirst($classPathParts[1]).'.inc.php';
- if(file_exists($classPath)) {
- require($classPath);
- } else {
- header("HTTP/1.0 404 Not Found");
- }
- }
- }
- );
- Core::loadPage();
- ?>
- -> modules/core/core.inc.php
- <?php
- class Core
- {
- public static function loadPage()
- {
- $moduleName;
- $moduleAction;
- $moduleParams;
- $url = $_GET['url'];
- $urlParts = explode('/', $url);
- if(!empty($urlParts)) {
- switch(count($urlParts)) {
- case 1:
- $moduleName = array_shift($urlParts);
- $moduleAction = "default";
- $moduleParams = null;
- break;
- case 2:
- $moduleName = array_shift($urlParts);
- $moduleAction = array_shift($urlParts);
- $moduleParams = null;
- break;
- default:
- $moduleName = array_shift($urlParts);
- $moduleAction = array_shift($urlParts);
- $moduleParams = $urlParts;
- break;
- }
- } else {
- $moduleName = "Main";
- $moduleAction = "default";
- $moduleParams = null;
- }
- $controllerClass = $moduleName.'_Controller';
- $controllerAction = $moduleAction.'Action';
- if(class_exists($controllerClass)) {
- $controller = new $controllerClass();
- if(method_exists($controller, $controllerAction)) {
- $controller->$controllerAction($moduleParams);
- } else {
- header("HTTP/1.0 404 Not Found");
- }
- } else {
- header("HTTP/1.0 404 Not Found");
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment