本文整理汇总了PHP中Dispatcher::url方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::url方法的具体用法?PHP Dispatcher::url怎么用?PHP Dispatcher::url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
/**
* Call route loads, process requested url and dispatchs to controllers
*/
public static function dispatch()
{
try {
self::$url = isset($_GET['url']) ? $_GET['url'] : '';
self::$dispatcher = new Pux\Mux();
self::loadRoutes();
// real dispatcher (Pux) call
$route = self::$dispatcher->dispatch('/' . self::$url);
// shorthand pointers to processed route variables
$vars = is_array($route) && array_key_exists(3, $route) && array_key_exists('vars', $route[3]) ? $route[3]['vars'] : array();
$default = is_array($route) && array_key_exists(3, $route) && array_key_exists('default', $route[3]) ? $route[3]['default'] : array();
// parse controller name from the processed route
$controller = ucfirst(!is_null($route[2]) && array_key_exists(0, $route[2]) ? $route[2][0] : (array_key_exists('controller', $vars) ? $vars['controller'] : (array_key_exists('controller', $default) ? $default['controller'] : DEFAULT_CONTROLLER_NAME)));
// all controller must have the Controller suffix
if (strlen($controller) < 10 || substr($controller, -10) != 'Controller') {
$controller .= 'Controller';
}
// let's instantiate the controller so if it not exists, should fire
// an exception and the rest of the code in this method won't run
$Controller = new $controller();
// parse method name from the processed route
$method = !is_null($route[2]) && array_key_exists(1, $route[2]) ? $route[2][1] : (array_key_exists('method', $vars) ? $vars['method'] : (array_key_exists('method', $default) ? $default['method'] : DEFAULT_CONTROLLER_METHOD));
// parse arguments to be sent to the controller method from the processed route
$args = !is_null($route[2]) && array_key_exists(2, $route[2]) ? $route[2][3] : (!is_null($route[3]) && array_key_exists('args', $vars) ? preg_split('/\\//', $vars['args']) : (!is_null($default) && array_key_exists('args', $default) ? $default['args'] : array()));
// there we go
call_user_func_array(array($Controller, $method), $args);
} catch (Exception $e) {
// TO-DO:
// probably we couldn't dispatch the request because of
// an unreachable controller method so we should show a
// 404 page or handle the exception in a proper way
error_log('Dispatcher::dispatch: ' . $e->getMessage());
}
}
示例2: url
function url($u)
{
return Dispatcher::url($u);
}