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


PHP Director::urlSegment方法代码示例

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


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

示例1: handleRequest

 /**
  * Handle an HTTP request, defined with a HTTPRequest object.
  *
  * @return HTTPResponse|string
  */
 protected static function handleRequest(HTTPRequest $request, Session $session)
 {
     krsort(Director::$rules);
     if (isset($_REQUEST['debug'])) {
         Debug::show(Director::$rules);
     }
     foreach (Director::$rules as $priority => $rules) {
         foreach ($rules as $pattern => $controllerOptions) {
             if (is_string($controllerOptions)) {
                 if (substr($controllerOptions, 0, 2) == '->') {
                     $controllerOptions = array('Redirect' => substr($controllerOptions, 2));
                 } else {
                     $controllerOptions = array('Controller' => $controllerOptions);
                 }
             }
             if (($arguments = $request->match($pattern, true)) !== false) {
                 // controllerOptions provide some default arguments
                 $arguments = array_merge($controllerOptions, $arguments);
                 // Find the controller name
                 if (isset($arguments['Controller'])) {
                     $controller = $arguments['Controller'];
                 }
                 // Pop additional tokens from the tokeniser if necessary
                 if (isset($controllerOptions['_PopTokeniser'])) {
                     $request->shift($controllerOptions['_PopTokeniser']);
                 }
                 // Handle redirections
                 if (isset($arguments['Redirect'])) {
                     return "redirect:" . Director::absoluteURL($arguments['Redirect'], true);
                 } else {
                     /*
                     if(isset($arguments['Action'])) {
                     	$arguments['Action'] = str_replace('-','',$arguments['Action']);
                     }
                     
                     if(isset($arguments['Action']) && ClassInfo::exists($controller.'_'.$arguments['Action']))
                     	$controller = $controller.'_'.$arguments['Action'];
                     */
                     if (isset($arguments['URLSegment'])) {
                         self::$urlSegment = $arguments['URLSegment'] . "/";
                     }
                     Director::$urlParams = $arguments;
                     $controllerObj = new $controller();
                     $controllerObj->setSession($session);
                     return $controllerObj->handleRequest($request);
                 }
             }
         }
     }
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:55,代码来源:Director.php

示例2: getControllerForURL

 static function getControllerForURL($url)
 {
     if (isset($_GET['debug_profile'])) {
         Profiler::mark("Director", "getControllerForURL");
     }
     $url = preg_replace(array('/\\/+/', '/^\\//', '/\\/$/'), array('/', '', ''), $url);
     $urlParts = split('/+', $url);
     krsort(Director::$rules);
     if (isset($_REQUEST['debug'])) {
         Debug::show(Director::$rules);
     }
     foreach (Director::$rules as $priority => $rules) {
         foreach ($rules as $pattern => $controller) {
             $patternParts = explode('/', $pattern);
             $matched = true;
             $arguments = array();
             foreach ($patternParts as $i => $part) {
                 $part = trim($part);
                 if (isset($part[0]) && $part[0] == '$') {
                     $arguments[substr($part, 1)] = isset($urlParts[$i]) ? $urlParts[$i] : null;
                     if ($part == '$Controller' && !class_exists($arguments['Controller'])) {
                         $matched = false;
                         break;
                     }
                 } else {
                     if (!isset($urlParts[$i]) || $urlParts[$i] != $part) {
                         $matched = false;
                         break;
                     }
                 }
             }
             if ($matched) {
                 if (substr($controller, 0, 2) == '->') {
                     if ($_REQUEST['debug'] == 1) {
                         Debug::message("Redirecting to {$controller}");
                     }
                     if (isset($_GET['debug_profile'])) {
                         Profiler::unmark("Director", "getControllerForURL");
                     }
                     return "redirect:" . Director::absoluteURL(substr($controller, 2), true);
                 } else {
                     if (isset($arguments['Controller']) && $controller == "*") {
                         $controller = $arguments['Controller'];
                     }
                     if (isset($_REQUEST['debug'])) {
                         Debug::message("Using controller {$controller}");
                     }
                     if (isset($arguments['Action'])) {
                         $arguments['Action'] = str_replace('-', '', $arguments['Action']);
                     }
                     if (isset($arguments['Action']) && ClassInfo::exists($controller . '_' . $arguments['Action'])) {
                         $controller = $controller . '_' . $arguments['Action'];
                     }
                     Director::$urlParams = $arguments;
                     $controllerObj = new $controller();
                     $controllerObj->setURLParams($arguments);
                     if (isset($arguments['URLSegment'])) {
                         self::$urlSegment = $arguments['URLSegment'] . "/";
                     }
                     if (isset($_GET['debug_profile'])) {
                         Profiler::unmark("Director", "getControllerForURL");
                     }
                     return $controllerObj;
                 }
             }
         }
     }
 }
开发者ID:ramziammar,项目名称:websites,代码行数:68,代码来源:Director.php


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