本文整理匯總了PHP中CHttpRequest::getPathInfo方法的典型用法代碼示例。如果您正苦於以下問題:PHP CHttpRequest::getPathInfo方法的具體用法?PHP CHttpRequest::getPathInfo怎麽用?PHP CHttpRequest::getPathInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CHttpRequest
的用法示例。
在下文中一共展示了CHttpRequest::getPathInfo方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getPathInfo
/**
* @return string Parsed path info without lang prefix.
*/
public function getPathInfo()
{
$langCode = null;
$pathInfo = parent::getPathInfo();
if ($this->_pathInfo === null) {
$pathInfo = parent::getPathInfo();
$parts = explode('/', $pathInfo);
/*
if (in_array($parts[0], Yii::app()->languageManager->getCodes()))
{
// Valid language code detected.
// Remove it from url path to make route work and activate lang
$langCode = $parts[0];
// If language code are is equal default show 404 page
if($langCode === Yii::app()->languageManager->default->code)
throw new CHttpException(404, Yii::t('core', 'Страница не найдена.'));
unset($parts[0]);
$pathInfo = implode($parts, '/');
}
*/
$this->_pathInfo = $pathInfo;
}
// Activate language by code
//Yii::app()->languageManager->setActive($langCode);
return $pathInfo;
}
示例2: parseUrl
/**
* Parses the user request.
* @param CHttpRequest $request The request application component.
* @return string The route (controllerID/actionID) and perhaps GET parameters in path format.
*/
public function parseUrl($request)
{
$route = $request->getQuery('r');
if (is_null($route)) {
$route = $request->getPathInfo();
}
$app = Yii::app()->getModule('herbie')->application;
try {
$path = $app['urlMatcher']->match($route);
} catch (Exception $ex) {
// Don't catch exception
}
if (!empty($path)) {
return 'herbie/page';
}
return parent::parseUrl($request);
}
示例3: getPathInfo
/**
* @return string
* @throws CHttpException
* @return string Parsed path info without lang prefix.
*/
public function getPathInfo()
{
$langCode = null;
$pathInfo = parent::getPathInfo();
if (null === $this->_pathInfo) {
$pathInfo = parent::getPathInfo();
$parts = explode('/', $pathInfo);
if (in_array($parts[0], Yii::app()->languageManager->getCodes())) {
// Valid language code detected.
// Remove it from url path to make route work and activate lang
$langCode = $parts[0];
// If language code is equal default - show 404 page
if ($langCode === Yii::app()->languageManager->default->code) {
throw new CHttpException(404, Yii::t('error', '404'));
}
unset($parts[0]);
$pathInfo = implode($parts, '/');
}
$this->_pathInfo = $pathInfo;
// Activate language by code
Yii::app()->languageManager->setActive($langCode);
}
return $pathInfo;
}
示例4: parseUrl
/**
* Parses the user request.
* @param CHttpRequest $request the request application component
* @return string the route (controllerID/actionID) and perhaps GET parameters in path format.
*/
public function parseUrl($request)
{
if ($this->getUrlFormat() === self::PATH_FORMAT) {
$rawPathInfo = $request->getPathInfo();
$pathInfo = $this->removeUrlSuffix($rawPathInfo, $this->urlSuffix);
foreach ($this->_rules as $i => $rule) {
if (is_array($rule)) {
$this->_rules[$i] = $rule = Gateway::createComponent($rule);
}
if (($r = $rule->parseUrl($this, $request, $pathInfo, $rawPathInfo)) !== false) {
return isset($_GET[$this->routeVar]) ? $_GET[$this->routeVar] : $r;
}
}
if ($this->useStrictParsing) {
throw new THoughtException("Unable to resolve the request '.{$pathInfo},').");
} else {
return $pathInfo;
}
} elseif (isset($_GET[$this->routeVar])) {
return $_GET[$this->routeVar];
} elseif (isset($_POST[$this->routeVar])) {
return $_POST[$this->routeVar];
} else {
return '';
}
}
示例5: parseUrl
/**
* Parses the user request.
* @param CHttpRequest $request the request application component
* @return string the route (controllerID/actionID) and perhaps GET parameters in path format.
*/
public function parseUrl($request)
{
if ($this->getUrlFormat() === self::PATH_FORMAT) {
$rawPathInfo = $request->getPathInfo();
$pathInfo = $this->removeUrlSuffix($rawPathInfo, $this->urlSuffix);
foreach ($this->_rules as $i => $rule) {
if (is_array($rule)) {
$this->_rules[$i] = $rule = Yii::createComponent($rule);
}
if (($r = $rule->parseUrl($this, $request, $pathInfo, $rawPathInfo)) !== false) {
return isset($_GET[$this->routeVar]) ? $_GET[$this->routeVar] : $r;
}
}
if ($this->useStrictParsing) {
throw new CHttpException(404, Yii::t('yii', 'Unable to resolve the request "{route}".', array('{route}' => $pathInfo)));
} else {
return $pathInfo;
}
} elseif (isset($_GET[$this->routeVar])) {
return $_GET[$this->routeVar];
} elseif (isset($_POST[$this->routeVar])) {
return $_POST[$this->routeVar];
} else {
return '';
}
}
示例6: getPathInfo
public function getPathInfo()
{
if ($this->_cleanPathInfo === null) {
$this->_cleanPathInfo = parent::getPathInfo();
$languages = array();
foreach ($this->languages as $k => $v) {
$languages[] = is_string($k) ? $k : $v;
}
$pattern = implode('|', $languages);
if (preg_match("#^({$pattern})\\b(/?)#", $this->_cleanPathInfo, $m)) {
$this->_cleanPathInfo = substr($this->_cleanPathInfo, strlen($m[1] . $m[2]));
$language = isset($this->languages[$m[1]]) ? $this->languages[$m[1]] : $m[1];
Yii::app()->language = $language;
YII_DEBUG && Yii::trace("Detected language '{$language}'", 'ext.localeurls');
if ($this->persistLanguage) {
Yii::app()->user->setState(self::LANGUAGE_KEY, $language);
$cookies = $this->cookies;
if ($this->languageCookieLifetime) {
$cookie = new CHttpCookie(self::LANGUAGE_KEY, $language);
$cookie->expire = time() + $this->languageCookieLifetime;
$cookies->add(self::LANGUAGE_KEY, $cookie);
}
}
if (!$this->redirectDefault && $language === $this->getDefaultLanguage()) {
$url = $this->getBaseUrl() . '/' . $this->_cleanPathInfo;
$queryString = $this->getQueryString();
if (!empty($queryString)) {
$url .= '?' . $queryString;
}
$this->redirect($url);
}
} else {
$language = null;
if ($this->persistLanguage) {
$language = Yii::app()->user->getState(self::LANGUAGE_KEY);
if ($language === null) {
$language = $this->getCookies()->itemAt(self::LANGUAGE_KEY);
}
}
if ($language === null && $this->detectLanguage) {
foreach ($this->preferredLanguages as $preferred) {
if (in_array($preferred, $this->languages)) {
$language = $preferred;
break;
}
}
}
if ($language === null || $language === $this->_defaultLanguage) {
if (!$this->redirectDefault) {
return $this->_cleanPathInfo;
} else {
$language = $this->_defaultLanguage;
}
}
$key = array_search($language, $this->languages);
if ($key && is_string($key)) {
$language = $key;
}
if (($baseUrl = $this->getBaseUrl()) === '') {
$this->redirect('/' . $language . $this->getRequestUri());
} else {
$this->redirect(strtr($this->getRequestUri(), array($baseUrl => $baseUrl . '/' . $language)));
}
}
}
return $this->_cleanPathInfo;
}