/**
  * @param Base $base
  * @internal param $config
  */
 function __construct($base)
 {
     $this->route_callback = Router::execute($base);
     if (is_callable($this->route_callback[0])) {
         call_user_func_array($this->route_callback[0], $this->route_callback[1]);
     } else {
         $base->load->controller($this->route_callback[0], array(), $this->route_callback[1], $this->route_callback[2]);
     }
 }
Example #2
0
 /**
      * Figure out where the user is trying to get to and route them to the appropriate controller/action.
 //剖析網址的規則, 取得 Controller/Action
 */
 public function router()
 {
     $r = new Router();
     // Configure the routes, where the user should go when they access the
     // specified URL structures. Default controller and action is set in the config.php file.
     $r->map('/', array('controller' => ROUTER_DEFAULT_CONTROLLER, 'action' => ROUTER_DEFAULT_ACTION));
     // Load instructions for basic routing and send the user on their way!
     $r->default_routes();
     $r->execute();
     // Extracting info about where the user is headed, in order to match the
     // URL with the correct controllers/actions.
     $controller = $r->controller;
     $model = $r->controller_name;
     $action = $r->action;
     $id = $r->id;
     $params = $r->params;
     // Returns an array(...)
     $matched = $r->route_found;
     // Bool, where True is if a route was found.
     if ($matched) {
         // If going to a site page, treat it in special manner, otherwise load
         // the appropriate controller/action and pass in the variables and
         // parameters specified by the URL.
         $controller_file = BASE_DIR . "/controller/{$controller}.php";
         if ($controller == "site") {
             $site = new Site();
             $site->login();
             $site->home();
         } elseif (file_exists($controller_file)) {
             include_once $controller_file;
             $site = new Site();
             $site->login();
             ${$controller} = new $model();
             if (method_exists(${$controller}, $action)) {
                 ${$controller}->controller['controller'] = $controller;
                 ${$controller}->controller['action'] = $action;
                 ${$controller}->id = $id;
                 ${$controller}->params = $params;
                 ${$controller}->{$action}();
             } else {
                 Site::load_page('error');
             }
         } else {
             Site::load_page('error');
         }
     } else {
         Site::home();
     }
 }
Example #3
0
 /**
  * Figure out where the user is trying to get to and route them to the
  * appropriate controller/action.
  */
 function router()
 {
     // Create a new Router instance.
     $r = new Router();
     // Configure the routes, where the user should go when they access the
     // specified URL structures. Default controller and action is set in the
     // config.php file.
     $r->map('/', array('controller' => ROUTER_DEFAULT_CONTROLLER, 'action' => ROUTER_DEFAULT_ACTION));
     $r->map('/user', array('controller' => 'user', 'action' => 'index'));
     $r->map('/login', array('controller' => 'user', 'action' => 'login'));
     $r->map('/logout', array('controller' => 'user', 'action' => 'logout'));
     $r->map('/signup', array('controller' => 'user', 'action' => 'register'));
     $r->map('/users/:id', array('controller' => 'users'), array('id' => '[\\d]{1,8}'));
     // Load instructions for basic routing and send the user on their way!
     $r->default_routes();
     $r->execute();
     // Extracting info about where the user is headed, in order to match the
     // URL with the correct controllers/actions.
     $controller = $r->controller;
     $model = $r->controller_name;
     $action = $r->action;
     $id = $r->id;
     $params = $r->params;
     // Returns an array(...)
     $matched = $r->route_found;
     // Bool, where True is if a route was found.
     if ($matched) {
         // If going to a site page, treat it in special manner, otherwise load
         // the appropriate controller/action and pass in the variables and
         // parameters specified by the URL.
         if ($controller == "site") {
             $site = new Site();
             $site->load_page($action);
         } elseif (file_exists(LIB_DIR . '/controllers/' . $controller . '.php')) {
             ${$controller} = new $model();
             if (method_exists(${$controller}, $action)) {
                 ${$controller}->{$action}($id, $params[0], $params[1]);
             } else {
                 Site::load_page('error');
             }
         } else {
             Site::load_page('error');
         }
     } else {
         Site::load_page('home');
     }
 }
    if (is_file(APP_PATH . "extensions/helpers/{$class}.php")) {
        return include APP_PATH . "extensions/helpers/{$class}.php";
    }
    if (is_file(CORE_PATH . "extensions/helpers/{$class}.php")) {
        return include CORE_PATH . "extensions/helpers/{$class}.php";
    }
    if (is_file(APP_PATH . "libs/{$class}.php")) {
        return include APP_PATH . "libs/{$class}.php";
    }
    if (is_file(CORE_PATH . "libs/{$class}/{$class}.php")) {
        return include CORE_PATH . "libs/{$class}/{$class}.php";
    }
    if ($class == 'kumbia_exception') {
        include CORE_PATH . 'kumbia/kumbia_exception.php';
    }
}
// @see Router
require CORE_PATH . 'kumbia/router.php';
// @see Controller
require APP_PATH . 'libs/app_controller.php';
// @see KumbiaView
require APP_PATH . 'libs/view.php';
// Ejecuta el request
try {
    // Dispatch y renderiza la vista
    View::render(Router::execute($url), $url);
} catch (KumbiaException $e) {
    KumbiaException::handle_exception($e);
}
// Fin del request
exit;
Example #5
0
$get = array_keys($_GET);
$route = array_shift($get);
/** Autoloader */
spl_autoload_register(function ($class) {
    $path = str_replace(__NAMESPACE__ . '\\', '', $class);
    $path = str_replace('\\', '/', $path);
    require_once $path . '.php';
});
Model::init();
//Router::route('install', ['Blog\AbstractController', 'install']);
//
Router::route('posts', ['Blog\\Controller\\Front', 'posts']);
//Router::route('edit/post/(\d+)', ['Blog\Controller\Front', 'form']);
//Router::route('delete/post/(\d+)', ['Blog\Controller\Front', 'delete']);
//Router::route('edit/post/', ['Blog\Controller\Front', 'form']);
//Router::route('new/post', ['Blog\Controller\Front', 'form']);
//
//Router::route('users', ['Blog\Controller\User', 'index']);
//Router::route('delete/user/(\d+)', ['Blog\Controller\User', 'delete']);
//Router::route('new/user', ['Blog\Controller\User', 'form']);
//Router::route('edit/user/', ['Blog\Controller\User', 'form']);
//Router::route('edit/user/(\d+)', ['Blog\Controller\User', 'form']);
Router::route('([a-z]+)/(index)');
Router::route('([a-z]+)/(single)/(\\d*)');
Router::route('([a-z]+)/(delete)/(\\d+)');
Router::route('([a-z]+)/(insert)');
Router::route('([a-z]+)/(edit)/(\\d*)');
Router::route('([a-z]+)/(save)/(\\d*)');
Router::execute($_SERVER['QUERY_STRING']);
Example #6
0
<?php

require __DIR__ . '/check_setup.php';
require __DIR__ . '/controllers/base.php';
require __DIR__ . '/lib/router.php';
if (file_exists('config.php')) {
    require 'config.php';
}
// Auto-refresh frequency in seconds for the public board view
defined('AUTO_REFRESH_DURATION') or define('AUTO_REFRESH_DURATION', 60);
$router = new Router();
$router->execute();
 public function index()
 {
     Router::execute("dashboard/");
 }
Example #8
0
File: index.php Project: anehx/blog
<?php

require_once __DIR__ . '/utils/Router.class.php';
require_once __DIR__ . '/controllers/Controller.class.php';
require_once __DIR__ . '/controllers/UserController.class.php';
require_once __DIR__ . '/controllers/BlogListController.class.php';
require_once __DIR__ . '/controllers/BlogController.class.php';
require_once __DIR__ . '/controllers/PostListController.class.php';
require_once __DIR__ . '/controllers/PostController.class.php';
require_once __DIR__ . '/controllers/CommentListController.class.php';
require_once __DIR__ . '/controllers/CommentController.class.php';
require_once __DIR__ . '/controllers/CategoryListController.class.php';
require_once __DIR__ . '/controllers/CategoryController.class.php';
require_once __DIR__ . '/controllers/RegisterController.class.php';
require_once __DIR__ . '/controllers/LoginController.class.php';
$router = new Router('\\/api\\/v1');
$router->route('\\/users\\/(\\d+)', 'UserController::handle');
$router->route('\\/blogs', 'BlogListController::handle');
$router->route('\\/blogs\\/(\\d+)', 'BlogController::handle');
$router->route('\\/posts', 'PostListController::handle');
$router->route('\\/posts\\/(\\d+)', 'PostController::handle');
$router->route('\\/comments', 'CommentListController::handle');
$router->route('\\/comments\\/(\\d+)', 'CommentController::handle');
$router->route('\\/categories', 'CategoryListController::handle');
$router->route('\\/categories\\/(\\d+)', 'CategoryController::handle');
$router->route('\\/register', 'RegisterController::handle');
$router->route('\\/login', 'LoginController::handle');
if (isset($_SERVER['REDIRECT_URL'])) {
    $router->execute(explode('?', $_SERVER['REDIRECT_URL'])[0]);
}
Controller::response(array(), 404, 'Route not found');
Example #9
0
<?php

define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(dirname(__FILE__)));
$url = empty($_GET['url']) ? 'index' : $_GET['url'];
require_once ROOT . DS . 'app' . DS . 'lib' . DS . 'init.php';
//  Criando as rotas dinamicamente
Router::route("/(\\w+)/?(\\w+)?/?(\\w+)?", function ($param0, $param1 = '', $param2 = '') {
    $params = func_get_args();
    $modelName = ucwords(strtolower($params[0]));
    try {
        $model = new $modelName();
        $controller = new Controller($model, $params[1]);
        $controller->{$params[1]}();
    } catch (Throwable $t) {
        // echo $t->getMessage();
        // var_dump($params);
    }
    $view = new View($model, "base");
    $view->render();
    return;
});
try {
    Router::execute("/" . $url);
} catch (Exception $e) {
    echo $e->getMessage();
}
Example #10
0
 public function process($request = array(), $params = array())
 {
     $query_string = $request['PATH'];
     return $this->router->execute($query_string, $request, $params);
 }
Example #11
0
<?php

// PHP 5.5.10
error_reporting(0);
define('BASEPATH', __DIR__);
// Подключаем роутер, он будет обрабатывать запросы,
// назначать им методы приложения или отображать страницу
// 404 для некооректных запросов
require_once BASEPATH . '/app/core/router.php';
// Подключаем контроллер проекта
require_once BASEPATH . '/app/draw.php';
// Инициализируем класс проекта (контроллер)
$draw = new Draw();
// Назначаем роуты приложения
Router::route('', 'imgList');
Router::route('list', 'imgList');
Router::route('edit', 'imgEdit');
Router::route('create', 'imgEdit');
Router::route('insert', 'ajaxInsert');
Router::route('update', 'ajaxUpdate');
// Запускаем роутер для нашего приложения
Router::execute($draw, $_GET['action']);
Example #12
0
session_start();
// includes the system routes. Define your own routes in this file
include ROOT_PATH . '/config/routes.php';
/**
 * Standard framework autoloader
 * @param string $className
 */
function autoloader($className)
{
    // controller autoloading
    if (strlen($className) > 10 && substr($className, -10) == 'Controller') {
        if (file_exists(ROOT_PATH . '/app/controllers/' . $className . '.php') == 1) {
            require_once ROOT_PATH . '/app/controllers/' . $className . '.php';
        }
    } else {
        if (file_exists(CMS_PATH . $className . '.php')) {
            require_once CMS_PATH . $className . '.php';
        } else {
            if (file_exists(ROOT_PATH . '/lib/' . $className . '.php')) {
                require_once ROOT_PATH . '/lib/' . $className . '.php';
            } else {
                require_once ROOT_PATH . '/app/models/' . $className . '.php';
            }
        }
    }
}
// activates the autoloader
spl_autoload_register('autoloader');
$router = new Router();
$router->execute($routes);
Example #13
0
require_once 'environment.default.php';
session_start();
include 'lib/redis/RedisClient.php';
include 'lib/redis/Redis.php';
include 'Router.php';
include 'controllers/ApplicationController.php';
include 'controllers/RedisController.php';
include 'controllers/iRedisType.php';
include 'bootstrap.php';
// http://blog.sosedoff.com/2009/07/04/simpe-php-url-routing-controller/
$r = new Router();
// create router instance
$r->map('/search', array('controller' => 'search', 'action' => 'index'));
$r->map('/', array('controller' => 'home'));
$r->default_routes();
$r->execute();
$class_name = $r->controller_name . 'Controller';
$path_to_controller = 'controllers/' . $class_name . '.php';
if (is_file($path_to_controller)) {
    require_once $path_to_controller;
} else {
    echo '<div class="error">Controller not found!</div>';
    exit;
}
$dispatch = new $class_name();
if (!method_exists($dispatch, $r->action)) {
    echo '<div class="error">Action <b>' . $r->action . '</b> not specified in <b>' . $r->controller_name . 'Controller</b></div>';
    exit;
} else {
    call_user_func_array(array($dispatch, "setParams"), array($r->params));
    call_user_func(array($dispatch, $r->action));