Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Map structure:
- --controllers
- --models
- --utils
- controller.php //namespace Utils
- model.php // namespace Utils
- router.php // namespace Utils
- --views
- index.php
- index.php:
- new Router()
- router.php:
- <?php
- namespace Utils;
- use Utils\Router;
- class Router {
- public function __construct() {
- if(isset($_GET['page']) && preg_match("/[a-zA-Z0-9]$/", str_replace("/", "", $_GET['page']))) {
- $parts = array_filter(explode('/', $_GET['page']), 'Utils\Router::modifiedsplit');
- $class_name = array_shift($parts);
- if(class_exists($class_name)) {
- $controller = new $class_name;
- $controller = ucfirst(strtolower($controller));
- if(count($parts) > 0 && method_exists($controller, $parts[0])) {
- $method = $parts[0];
- $controller->$method();
- } else {
- $controller->start();
- }
- } else {
- // TODO link to 404
- echo 'no class with that name found';
- }
- } else {
- require 'controllers/index.php';
- new Controllers\Index().start();
- }
- }
- public static function modifiedsplit($var) {
- return $var != "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement