本文整理匯總了PHP中Dispatcher::params方法的典型用法代碼示例。如果您正苦於以下問題:PHP Dispatcher::params方法的具體用法?PHP Dispatcher::params怎麽用?PHP Dispatcher::params使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::params方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getParams
/**
* 獲得動作參數
*/
public static function getParams()
{
//此條URL規則作廢URL http://sk.com/sk80/index.php?job=archive&action=archive&arg=alias_google-out-china&page=1
//URL http://sk.com/sk80/index.php?job=archive&action=archive&alias=google-out-china&page=1
//處理有分頁的情況
$parmas = array();
$params = self::$request;
if (array_key_exists('job', $params)) {
unset($params['job']);
}
if (array_key_exists('action', $params)) {
unset($params['action']);
}
return self::$params = $params;
}
示例2: dispatch
public static function dispatch($requested_url = null, $default = null)
{
Flash::init();
// If no url passed, we will get the first key from the _GET array
// that way, index.php?/controller/action/var1&email=example@example.com
// requested_url will be equal to: /controller/action/var1
if ($requested_url === null) {
$pos = strpos($_SERVER['QUERY_STRING'], '&');
if ($pos !== false) {
$requested_url = substr($_SERVER['QUERY_STRING'], 0, $pos);
} else {
$requested_url = $_SERVER['QUERY_STRING'];
}
}
// If no URL is requested (due to someone accessing admin section for the first time)
// AND $default is setAllow for a default tab
if ($requested_url == null && $default != null) {
$requested_url = $default;
}
// Requested url MUST start with a slash (for route convention)
if (strpos($requested_url, '/') !== 0) {
$requested_url = '/' . $requested_url;
}
self::$requested_url = $requested_url;
// This is only trace for debugging
self::$status['requested_url'] = $requested_url;
// Make the first split of the current requested_url
self::$params = self::splitUrl($requested_url);
// Do we even have any custom routing to deal with?
if (count(self::$routes) === 0) {
return self::executeAction(self::getController(), self::getAction(), self::getParams());
}
// Is there a literal match? If so we're done
if (isset(self::$routes[$requested_url])) {
self::$params = self::splitUrl(self::$routes[$requested_url]);
return self::executeAction(self::getController(), self::getAction(), self::getParams());
}
// Loop through the route array looking for wildcards
foreach (self::$routes as $route => $uri) {
// Convert wildcards to regex
if (strpos($route, ':') !== false) {
$route = str_replace(':any', '(.+)', str_replace(':num', '([0-9]+)', $route));
}
// Does the regex match?
if (preg_match('#^' . $route . '$#', $requested_url)) {
// Do we have a back-reference?
if (strpos($uri, '$') !== false && strpos($route, '(') !== false) {
$uri = preg_replace('#^' . $route . '$#', $uri, $requested_url);
}
self::$params = self::splitUrl($uri);
// We found it, so we can break the loop now!
break;
}
}
return self::executeAction(self::getController(), self::getAction(), self::getParams());
}