本文整理汇总了PHP中core\Router::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::parse方法的具体用法?PHP Router::parse怎么用?PHP Router::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core\Router
的用法示例。
在下文中一共展示了Router::parse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$app = App::getInstance();
// On initialise l'objet Request
if ($_ENV['USE_ROUTES']) {
require '../Config/routes.php';
$this->request = Router::run(new Request($app));
} else {
$this->request = new Request($app);
}
// On parse l'url (définition du controller, action,...)
Router::parse($this->request);
// On affiche les erreurs ?
Debug::set();
// On charge le bon controller
try {
$controller = $this->loadController();
} catch (SwithException $e) {
(new SwithError(['message' => "Le controller {$this->request->controller} est introuvable", "title" => "Controlleur introuvable"]))->display();
}
if (method_exists($controller, "beforeRender")) {
$controller->beforeRender();
}
// On appelle la fonction
$action = $this->request->getAction();
$availablesActions = array_diff(get_class_methods($controller), get_class_methods(get_parent_class($controller)));
if (in_array($action, $availablesActions)) {
call_user_func_array([$controller, $action], $this->request->params);
} else {
(new SwithError(['message' => "Le controller {$this->request->controller} n'a pas de methode {$action}", "title" => "Methode introuvable"]))->display();
}
$controller->render($controller->view);
}
示例2: Debug
function __construct()
{
LoaderJavascript::add("debug", "controller.init", Conf::$debug);
LoaderJavascript::add("test", "controller.init");
$this->debug = new Debug($this);
$this->debug->handle_errors();
if (!Conf::$install) {
$this->roleUser();
}
$this->request = new Request();
Router::parse($this->request->url, $this->request);
}
示例3: Request
function __construct()
{
$this->request = new Request();
Router::parse($this->request->url, $this->request);
$controller = $this->loadController();
$action = $this->request->action;
foreach ($this->request->params as $param) {
$this->parametre .= $param . ", ";
}
$this->parametre = rtrim($this->parametre, ", ");
if (empty($this->parametre)) {
$controller->{$action}();
} else {
$controller->{$action}($this->parametre);
}
}