Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Run application
- require 'application/app.php';
- $app = new App();
- $app->run();
- <?php
- class App {
- public function run() {
- // Determine request path
- $path = $_SERVER['REQUEST_URI'];
- // Load routes
- require_once 'routes.php';
- // Match this request to a route
- if(isset(Routes::$routes[$path])) {
- } else {
- // Use default route
- $controller = Routes::$routes['/'][0];
- $action = Routes::$routes['/'][1];
- }
- // Check if controller exists
- if(file_exists('controllers/' . $controller . '.php')) {
- // Include and instantiate controller
- require_once 'controllers/' . $controller . '.php';
- $controller = new $controller . 'Controller';
- // Run method for this route
- if(method_exists($controller, $action)) {
- return $controller->$action();
- } else {
- die('Method ' . $action . ' missing in controller ' . $controller);
- }
- } else {
- die('Controller ' . $controller . 'Controller missing');
- }
- }
- }
- <?php
- class Routes {
- public static $routes = array(
- '/' => array('Pages', 'home')
- );
- }
- /application
- /controllers
- Pages.php
- /models
- /views
- app.php
- routes.php
- // Run application
- define('ROOT', dirname(__FILE__) );
- require ROOT . '/application/app.php';
- $app = new App();
- $app->run();
- // Check if controller exists
- if(file_exists(ROOT . '/application/controllers/' . $controller . '.php')) {
- // Include and instantiate controller
- require_once ROOT. '/application/controllers/' . $controller . '.php';
- $controller = new $controller . 'Controller';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement