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


PHP RequestUtil::GetBaseURL方法代码示例

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


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

示例1: RenderRSS

 /**
  * Render an array of IRSSFeedItem objects as an RSS feed
  * @param array $feedItems array of IRSSFeedItem objects
  * @param string $feedTitle
  * @param string $feedDescription
  */
 protected function RenderRSS(array $feedItems, $feedTitle = "RSS Feed", $feedDescription = "RSS Feed")
 {
     require_once 'verysimple/RSS/Writer.php';
     require_once 'verysimple/RSS/IRSSFeedItem.php';
     $baseUrl = RequestUtil::GetBaseURL();
     $rssWriter = new RSS_Writer($feedTitle, $baseUrl, $feedDescription);
     $rssWriter->setLanguage('us-en');
     $rssWriter->addCategory("Items");
     if (count($feedItems)) {
         $count = 0;
         foreach ($feedItems as $item) {
             $count++;
             if ($item instanceof IRSSFeedItem) {
                 $rssWriter->addItem($item->GetRSSTitle(), $item->GetRSSLink($baseUrl), $item->GetRSSDescription(), $item->GetRSSAuthor(), date(DATE_RSS, $item->GetRSSPublishDate()), null, $item->GetRSSGUID());
             } else {
                 $rssWriter->addItem("Item {$count} doesn't implment IRSSFeedItem", "about:blank", '', 'Error', date(DATE_RSS));
             }
         }
     } else {
         $rssWriter->addItem("No Items", "about:blank", '', 'No Author', date(DATE_RSS));
     }
     $rssWriter->writeOut();
 }
开发者ID:niceboy120,项目名称:phreeze,代码行数:29,代码来源:Controller.php

示例2: GetUrl

 /**
  * @inheritdocs
  */
 public function GetUrl($controller, $method, $params = '', $requestMethod = "")
 {
     $found = false;
     // params may be either an array of key/value pairs, or a string in the format key=val&key=val&key=val
     if (!is_array($params)) {
         parse_str($params, $params);
     }
     // The app root url is needed so we can return the fully qualified URL
     $url = $this->appRootUrl ? $this->appRootUrl : RequestUtil::GetBaseURL();
     // normalize the url so that there are no trailing slashes
     $url = rtrim($url, '/');
     // enumerate all of the routes in the map and look for the first one that matches
     foreach ($this->routeMap as $key => $value) {
         list($routeController, $routeMethod) = explode(".", $value["route"]);
         $routeRequestMethodArr = explode(":", $key, 2);
         $routeRequestMethod = $routeRequestMethodArr[0];
         // In order to match a route it needs to meet 3 conditions:
         // 1. controller and method match
         // 2. the requestMethod is either a match or one or the other is a wildcard
         // 3. the number of parameters is equal
         if ($routeController == $controller && $routeMethod == $method && ($requestMethod == "" || $routeRequestMethod == "*" || $routeRequestMethod == $requestMethod) && (!array_key_exists("params", $value) || count($params) == count($value["params"]))) {
             $keyArr = explode('/', $key);
             // strip the request method off the key:
             $reqMethodAndController = explode(":", $keyArr[0]);
             $keyArr[0] = count($reqMethodAndController) == 2 ? $reqMethodAndController[1] : $reqMethodAndController[0];
             // merge the parameters passed in with the routemap's path
             // example: path is user/(:num)/events and parameters are [userCode]=>111
             // this would yield an array of [0]=>user, [1]=>111, [2]=>events
             if (array_key_exists("params", $value)) {
                 foreach ($value["params"] as $rKey => $rVal) {
                     if (!array_key_exists($rKey, $params)) {
                         throw new Exception("Missing parameter '{$rKey}' for route {$controller}.{$method}");
                     }
                     $keyArr[$value["params"][$rKey]] = $params[$rKey];
                 }
             }
             // put the url together:
             foreach ($keyArr as $urlPiece) {
                 $url = $url . ($urlPiece != '' ? "/{$urlPiece}" : '');
             }
             // no route, just a request method? RESTful to add a trailing slash:
             if ($routeRequestMethodArr[1] == "") {
                 $url . "/";
             }
             $found = true;
             break;
         }
     }
     if (!$found) {
         throw new Exception('No route found for ' . ($requestMethod ? $requestMethod : '*') . ":{$controller}.{$method}" . ($params ? '?' . implode('&', $params) : ''));
     }
     return $url;
 }
开发者ID:cleomardasilva,项目名称:phreeze,代码行数:56,代码来源:GenericRouter.php

示例3: GetUrl

 /**
  * @inheritdocs
  */
 public function GetUrl($controller, $method, $params = '', $requestMethod = "")
 {
     $found = false;
     // $requestMethod = RequestUtil::GetMethod();
     if ($params == '') {
         $params = array();
     }
     if (!is_array($params)) {
         $pairs = explode('&', $params);
         $params = array();
         foreach ($pairs as $pair) {
             $keyval = explode('=', $pair);
             $params[$keyval[0]] = count($keyval) > 1 ? $keyval[1] : '';
         }
     }
     // if an appRootUrl was provided then use that, otherwise figure it out based on the root url
     $url = $this->appRootUrl ? $this->appRootUrl : RequestUtil::GetBaseURL();
     // normalize url by stripping trailing slash
     while (substr($url, -1) == '/') {
         $url = substr($url, 0, -1);
     }
     foreach ($this->routes as $key => $value) {
         list($routeController, $routeMethod) = explode(".", $value["route"]);
         $keyRequestMethodArr = explode(":", $key, 2);
         $keyRequestMethod = $keyRequestMethodArr[0];
         // echo "$routeController:$controller $routeMethod:$method $keyRequestMethod:$requestMethod)<br/>";
         if ($routeController == $controller && $routeMethod == $method && ($requestMethod == "" || $keyRequestMethod == $requestMethod) && (!array_key_exists("params", $value) || count($params) == count($value["params"]))) {
             $keyArr = explode('/', $key);
             // strip the request method off the key:
             // we can safely access 0 here, as there has to be params to get here:
             $reqMethodAndController = explode(":", $keyArr[0]);
             $keyArr[0] = count($reqMethodAndController) == 2 ? $reqMethodAndController[1] : $reqMethodAndController[0];
             // merge the parameters passed in with the routemap's path
             // example: path is user/(:num)/events and parameters are [userCode]=>111
             // this would yield an array of [0]=>user, [1]=>111, [2]=>events
             if (array_key_exists("params", $value)) {
                 foreach ($value["params"] as $rKey => $rVal) {
                     if (!array_key_exists($rKey, $params)) {
                         throw new Exception('Missing parameter "' . $rKey . "' for route " . $controller . '.' . $method);
                     }
                     $keyArr[$value["params"][$rKey]] = $params[$rKey];
                 }
             }
             // put the url together:
             foreach ($keyArr as $urlPiece) {
                 $url = $url . ($urlPiece != '' ? "/{$urlPiece}" : '');
             }
             // no route, just a request method? RESTful to add a trailing slash:
             if ($keyRequestMethodArr[1] == "") {
                 $url = $url . "/";
             }
             $found = true;
             break;
         }
     }
     // we stripped this at the beginning, need to add it back
     if (!$found) {
         // $url = $url . "/";
         throw new Exception("No route found for " . $controller . '.' . $method . ($params ? '?' . implode('&', $params) : ''));
     }
     return $url;
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:65,代码来源:GenericRouter.php


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