本文整理汇总了PHP中Router::params方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::params方法的具体用法?PHP Router::params怎么用?PHP Router::params使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::params方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public static function init()
{
$url = $_SERVER['REQUEST_URI'];
$isCustom = false;
if (count(self::$rules)) {
foreach (self::$rules as $ruleKey => $ruleData) {
$params = self::ruleMatch($ruleKey, $url);
if ($params) {
self::$controller = $ruleData['controller'];
self::$action = $ruleData['action'];
self::$params = $params;
$isCustom = true;
break;
}
}
}
if (!$isCustom) {
self::defaultRoutes($url);
}
if (!strlen(self::$controller)) {
self::$controller = 'site';
}
if (!strlen(self::$action)) {
self::$action = '';
}
if (self::$action == ':site') {
self::$action = self::getParam("site");
}
}
示例2: Dispatch
/**
* Обработка переданного URL
* Dispatch received URL
*/
public static function Dispatch($requestedUrl = null)
{
// Если URL не передан, берем его из REQUEST_URI
if ($requestedUrl === null) {
$uri = reset(explode('?', $_SERVER["REQUEST_URI"]));
$requestedUrl = urldecode(rtrim($uri, '/'));
}
self::$requestedUrl = $requestedUrl;
// если URL и маршрут полностью совпадают
if (isset(self::$routes[$requestedUrl])) {
self::$params = self::SplitUrl(self::$routes[$requestedUrl]);
return self::ExecuteAction();
}
foreach (self::$routes as $route => $uri) {
// Заменяем wildcards на рег. выражения
if (strpos($route, ':') !== false) {
$route = str_replace(':any', '(.+)', str_replace(':num', '([0-9]+)', $route));
}
if (preg_match('#^' . $route . '$#', $requestedUrl)) {
if (strpos($uri, '$') !== false && strpos($route, '(') !== false) {
$uri = preg_replace('#^' . $route . '$#', $uri, $requestedUrl);
}
self::$params = self::SplitUrl($uri);
break;
// URL обработан!
}
}
return self::ExecuteAction();
}
示例3: parse
public static function parse($url)
{
$url = rtrim($url, '/');
$url = explode('/', $url);
if ($url[0]) {
self::$name = ucfirst(strtolower($url[0]));
}
self::$method = $url[1];
self::$params = array();
if (count($url) > 2) {
//есть параметры
for ($i = 2; $i < count($url); $i++) {
self::$params[] = $url[$i];
}
}
}
示例4: start
public static function start()
{
$r = !empty($_GET['routes']) ? $_GET['routes'] : '';
self::$routes = explode('/', $r);
$params = self::$routes;
unset(self::$params[0], self::$params[1]);
switch (self::$routes[0]) {
case 'module1':
case 'module2':
unset(self::$params[2]);
self::$params = array_values($params);
self::module();
break;
default:
self::$params = array_values($params);
self::getCtrlNames();
self::model();
self::controller();
}
}
示例5: setParams
public static function setParams($arr)
{
self::$params = $arr;
}
示例6: init
private function init()
{
//get user requested route
if (isset($_GET['node'])) {
//define route without parameters (helps with showing base URI request)
$route = $_GET['node'];
self::$route = $route;
//break requested route into chunks in array
$route_chunks = explode("/", $route);
//define controller
$controller = $route_chunks[0];
self::$controller = $controller;
//define controller directory
$controller_dir = CONTROLLER_DIR . $controller;
self::$controller_dir = $controller_dir;
//define format
if (!empty($route_chunks[1])) {
$format = $route_chunks[1];
self::$format = $format;
}
//define if group has been requested
if (!empty($route_chunks[2])) {
$group = $route_chunks[2];
self::$group = $group;
}
//define parameters - get full url etc and extract all strings after &..
global $settings;
$request_uri = $settings['request_uri'];
//break requested route into chunks in array
$route_params = explode("&", $request_uri);
//remove first value from array & return $route_params as just parameters
$params_shift = array_shift($route_params);
//update $params array
foreach ($route_params as $val) {
$param_chunks = explode("=", $val);
$params[$param_chunks[0]] = $param_chunks[1];
}
if (isset($params)) {
self::$params = $params;
} else {
self::$params = null;
}
}
}
示例7: testClosures
public function testClosures()
{
$router = new Router($this->collection);
$router->handle('closure/123/alpha');
$closure = $router->controllerName();
$expects = call_user_func_array($closure, $router->params());
$this->assertTrue(is_callable($router->controllerName()));
$this->assertEquals($expects, '123-alpha');
}
示例8: _init
private function _init()
{
$route = $this->_set_route();
$route = substr($route, -1, 1) == "/" ? substr($route, 0, -1) : $route;
$route = $route ? explode("/", $route) : null;
// define the controller directory
if (isset(self::$config_route['controller_dir_in_route']) && self::$config_route['controller_dir_in_route'] === true) {
if (is_array($route) && count($route)) {
self::$controller_dir = array_shift($route);
} elseif (isset(self::$config_route["default_controller_dir"])) {
self::$config_route["default_controller_dir"];
} else {
trigger_error("ROUTER: DEFAULT CONTROLLER DIR NOT SET");
}
}
// define the controller
if (is_array($route) && count($route)) {
self::$controller = array_shift($route);
} elseif (isset(self::$config_route['default_controller'])) {
self::$controller = self::$config_route["default_controller"];
} else {
trigger_error("ROUTER: DEFAULT CONTROLLER NOT SET");
}
// define action
if (is_array($route) && count($route)) {
self::$action = array_shift($route);
} elseif (isset(self::$config_route['default_action'])) {
self::$action = self::$config_route['default_action'];
} else {
trigger_error("ROUTER: DEFAULT ACTION NOT SET");
}
// define the parameters
if ($route) {
self::$params = $route;
}
}
示例9: init
static function init()
{
$uri = str_replace(Conf::$BASE_URL, '', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
self::$params = $_GET || [];
self::$uri = strtok($uri, '?');
}