本文整理汇总了PHP中router::route方法的典型用法代码示例。如果您正苦于以下问题:PHP router::route方法的具体用法?PHP router::route怎么用?PHP router::route使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类router
的用法示例。
在下文中一共展示了router::route方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
router::route('/blog/:arg', function ($arg) {
echo 'Argument: ' . $arg;
}, 'GET', 'blog');
router::route('/blog/*', function () {
echo 'CatchAll';
});
router::route('/blog/arg', function () {
echo 'NoArg';
});
router::route('/test.php', function () {
echo 'test.php';
});
router::route('/proiecs/aed[]te\\*', function () {
echo '/proiecs/aed[]te\\*';
});
router::route('/proiecs/:ala/bala/:korhaz/:edit/:buha', function ($arg1, $arg2, $arg3) {
echo 'proiecs ' . $arg1 . $arg2 . $arg3;
}, 'GET', 'proiecs');
router::route('/proiecs/asfv', function () {
echo '/proiecs/asfv/';
});
router::route(' /infinity', function () {
echo 'infinity';
}, 'GET', 'infinity');
router::route('/infinity/ourubors/ternary', function () {
echo '/infinity/ourubors/ternary';
}, 'GET', 'infinity2');
router::set('BASE', 'framework');
}
示例2: run
public static function run()
{
spl_autoload_register(__CLASS__ . "::" . 'autoload');
if (app_config::$use_db == true) {
db::set_db_config(app_config::$db);
}
url::init(app_config::$url);
router::route(app_config::$router, app_config::$re_route);
}
示例3: findroute
static function findroute()
{
$vars = array();
$elts = array();
router::$url = str_replace(_URL_ . '/', '', 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI']);
foreach (router::$routes as $name => &$route) {
if (preg_match($route['route'], router::$url)) {
router::$route = $name;
if (preg_match($route['route'], router::$url, $vars)) {
foreach ($vars as $k => $v) {
if (!is_numeric($k)) {
$elts[$k] = $v;
}
}
}
// si des droits on étais définis dans le router
if (isset($route['rights'])) {
if (is_array($route['rights'])) {
// on contrôle si REQUEST_METHOD existe
if (isset($_SERVER['REQUEST_METHOD'])) {
$requestMethod = $_SERVER['REQUEST_METHOD'];
if (isset($route['rights'][$requestMethod])) {
$rights = $route['rights'][$requestMethod];
} else {
trigger_error("methode " . $requestMethod . " invalide", E_USER_ERROR);
}
} else {
trigger_error("REQUEST_METHOD obligatoire", E_USER_ERROR);
}
} else {
$rights = $route['rights'];
}
} else {
$rights = false;
}
if (isset($route['module'])) {
router::CallController($route['module'], $elts, $rights);
}
if (isset($route['redirect'])) {
router::Redirect($route['redirect']);
}
break;
}
}
}
示例4: __construct
public function __construct()
{
/**
* Get the database and set the config
*/
$db = new database();
$db->setup($a = array('hostname' => 'localhost', 'username' => 'govhack', 'password' => 'govhack', 'database' => 'govhack_ip'))->connect();
/**
* Load the page controllers
*/
$search = new search($db);
$index = new index();
$about = new about();
/**
* Get the application router
*/
$router = new router();
$router->add('/', $index)->add('/index', $index)->add('/about', $about)->add('/search', $search)->add('/*', $search);
$router->route();
}
示例5: route
private static $method;
private static $params;
public static function route()
{
self::$URI = isset($_SERVER['REDIRECT_URL']) ? explode('/', $_SERVER['REDIRECT_URL']) : NULL;
self::$class = isset(self::$URI[URI_Level + 0]) ? self::$URI[URI_Level + 0] : 'main';
self::$method = isset(self::$URI[URI_Level + 1]) ? self::$URI[URI_Level + 1] : 'index';
$file_path = 'controllers/' . self::$class . '.php';
if (!file_exists($file_path)) {
self::$method = self::$class;
self::$class = 'main';
self::$params = isset(self::$URI[URI_Level + 1]) ? array_slice(self::$URI, URI_Level + 1) : array();
} else {
self::$params = isset(self::$URI[URI_Level + 2]) ? array_slice(self::$URI, URI_Level + 1) : array();
}
$file_path = 'controllers/' . self::$class . '.php';
include_once $file_path;
if (!method_exists(self::$class, self::$method)) {
//echo '404';
//echo self::$class, self::$method;
show_404();
}
//Static Way
//call_user_func_array(array(self::$class,self::$method),self::$params);
//Normal?
$class = new self::$class();
call_user_func_array(array($class, self::$method), self::$params);
}
}
router::route();
示例6: route
/**
* @see router::route
*/
public static function route($pattern, $funcs, $http = 'GET', $name = FALSE)
{
if (!class_exists('router', FALSE)) {
include_once 'router.php';
}
router::route($pattern, $funcs, $http, $name);
}
示例7: App
<?php
/**
* miniJSON
* - a very super simple, basic json php framework.
*/
error_reporting(E_ALL);
// New app
require 'app.php';
$app = new App();
// Set doc root
$root = '/miniJSONApp/miniJSON';
// Prod
$root = '/angularjs-crud-test/miniJSON';
// Dev
// Init routes, create router and route
require 'routes.php';
require 'router.php';
$router = new router($app, $root, $routes);
$router->route();