当前位置: 首页>>代码示例>>PHP>>正文


PHP router::perform_controller_action方法代码示例

本文整理汇总了PHP中router::perform_controller_action方法的典型用法代码示例。如果您正苦于以下问题:PHP router::perform_controller_action方法的具体用法?PHP router::perform_controller_action怎么用?PHP router::perform_controller_action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在router的用法示例。


在下文中一共展示了router::perform_controller_action方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: route

 static function route()
 {
     $url = explode('?', $_SERVER['REQUEST_URI']);
     $path = mb_strtolower($url[0]);
     while (substr($path, -1) == '/') {
         $path = mb_substr($path, 0, mb_strlen($path) - 1);
     }
     $path_components = explode('/', $path);
     //default actions are called 'index'
     $action = "index";
     //Handle home page requests
     if (count($path_components) == 1) {
         router::perform_controller_action("home", $action, array(), array());
     }
     //Loop through all the routes we defined in route.php, and try to find one that matches our request
     foreach ($GLOBALS['routes'] as $route => $controller) {
         $route_components = explode("/", $route);
         $action = "index";
         $i = 0;
         $objects = array();
         $goodRoute = true;
         $path_components = array_pad($path_components, count($route_components), '');
         $parameters = array();
         //Handle routes that call a specific action
         $controller_action_array = explode(":", $controller);
         $controller = $controller_action_array[0];
         if (count($controller_action_array) == 2) {
             $action = $controller_action_array[1];
         }
         //Loop through each component of this route until we find a part that doesn't match, or we run out of url
         foreach ($route_components as $route_component) {
             //This part of the route is a named parameter
             if (substr($route_component, 0, 1) == ":") {
                 $parameters[substr($route_component, 1)] = $path_components[$i];
                 //This part of the route is an action for a controller
             } elseif ($route_component == "[action]") {
                 if ($path_components[$i] != "") {
                     $action = str_replace("-", "_", $path_components[$i]);
                 }
                 //This part of the route will require that we create an object
             } elseif (substr($route_component, 0, 1) == "(" && substr($route_component, -1, 1) == ")") {
                 $reflection_obj = new ReflectionClass(substr($route_component, 1, strlen($route_component) - 2));
                 $object = $reflection_obj->newInstanceArgs(array($path_components[$i]));
                 $objects[] = $object;
                 //Part of the url that isn't an action or an object didn't match, this definitely isn't the right route
             } elseif ($route_component != $path_components[$i] && str_replace("-", "_", $route_component) != $path_components[$i]) {
                 //echo "Bad match: ".str_replace("-","_",$route_component)." != ".$path_components[$i]."<br />";
                 $goodRoute = false;
                 break;
             }
             $i++;
         }
         //This route is a match for our request, let's get the controller working on it
         if ($goodRoute && ($i >= count($path_components) || $path_components[$i] == "")) {
             router::perform_controller_action($controller, $action, $objects, $parameters);
         }
     }
     error_404();
 }
开发者ID:javier-nogales,项目名称:php-mvc-router,代码行数:59,代码来源:router.php


注:本文中的router::perform_controller_action方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。