本文整理汇总了PHP中yii\web\Request::getPathInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getPathInfo方法的具体用法?PHP Request::getPathInfo怎么用?PHP Request::getPathInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\web\Request
的用法示例。
在下文中一共展示了Request::getPathInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseRequest
/**
* Parses the given request and returns the corresponding route and parameters.
* @param UrlManager $manager the URL manager
* @param Request $request the request component
* @return array|boolean the parsing result. The route and the parameters are returned as an array.
* If false, it means this rule cannot be used to parse this path info.
*/
public function parseRequest($manager, $request)
{
foreach ($this->skip as $item) {
if (strpos($request->getPathInfo(), $item) !== false) {
return false;
}
}
$path = $request->getPathInfo();
$redirect = false;
// Слэш в конце
if (substr($path, -1) == '/') {
$redirect = true;
$path = trim($path, '/');
}
// Двойной слэш
if (strpos($path, '//') !== false) {
$redirect = true;
$path = str_replace('//', '/', $path);
}
// Символы в верхнем регистре
if (($tmpUrl = strtolower($path)) !== $path) {
$redirect = true;
$path = $tmpUrl;
}
if ($redirect) {
Yii::$app->response->redirect([$path], 301);
Yii::$app->end();
}
return false;
}
示例2: parseRequest
/**
* Parses the given request and returns the corresponding route and parameters.
* @param UrlManager $manager the URL manager
* @param Request $request the request component
* @return array|boolean the parsing result. The route and the parameters are returned as an array.
* If false, it means this rule cannot be used to parse this path info.
*/
public function parseRequest($manager, $request)
{
foreach ($this->skip as $item) {
if (strpos($request->getPathInfo(), $item) !== false) {
return false;
}
}
/** @var UrlRoute $model */
$model = $this->modelClass;
$model = $model::find()->andWhere(['path' => $request->getPathInfo()])->one();
if ($model == null) {
return false;
}
if ($model->checkAction($model::ACTION_INDEX)) {
return [$model->getRoute()];
} elseif ($model->checkAction($model::ACTION_VIEW)) {
return [$model->getRoute(), ['id' => $model->object_id]];
} elseif ($model->checkAction($model::ACTION_REDIRECT)) {
$url = $model->url_to;
if (strpos($url, 'http://') === false) {
$url = [$url];
}
Yii::$app->response->redirect($url, $model->http_code);
Yii::$app->end();
}
return false;
}
示例3: parseRequest
/**
* Parses the given request and returns the corresponding route and parameters.
*
* @param UrlManager $manager the URL manager
* @param Request $request the request component
*
* @return array|boolean the parsing result. The route and the parameters are returned as an array.
* If false, it means this rule cannot be used to parse this path info.
*/
public function parseRequest($manager, $request)
{
echo '<pre>==== BeeUrlRule ===<br>';
print_r('PathInfo = ' . $request->getPathInfo());
echo '<br>';
print_r('Url = ' . $request->getUrl());
echo '<br>======================</pre>';
$items = Yii::$app->getSiteMenu()->getMenu();
// Parse SEF URL
if (Yii::$app->urlManager->enablePrettyUrl == TRUE) {
$route = $request->getPathInfo();
/*
* Пошаговый парсинг меню
* Последне найденный записывается в переменную $found
*/
$found = null;
foreach ($items as $item) {
if ($item->path && BeeString::strpos($route, $item->path) === 0) {
// Exact route match. We can break iteration because exact item was found.
if ($item->path == $route) {
$found = $item;
break;
}
// Partial route match. Item with highest level takes priority.
if (!$found || $found->level < $item->level) {
$found = $item;
}
}
}
/*
* Если мы нашли конечный пункт меню и его адрес полностью собпадает,
* то формируем и возвращаем ссылку на этот пункт меню
* иначе берем компонент в @found и продолжаем поиск уже по этому компоненту.
*/
if (BeeString::strpos($route, $found->path) === 0) {
$extAction = $found->query[0];
// site/index
$url = ['path' => $found->query['path'], 'id' => $found->query['id']];
return [$extAction, $url];
} else {
echo '<pre>';
print_r('------------------- Еще не все распарсил -------------------');
echo '</pre>';
}
//echo '<br><br><br><pre>';
//print_r($found);
//echo '</pre><br><br><br>';
echo '<br><pre>Сделать парсинг для страниц, отсутствующих в меню';
echo '<br>======================</pre>';
} else {
// Parse RAW URL
return FALSE;
}
echo '<pre><<< Стандартный парсино Yii >>></pre>';
return FALSE;
//return ['site/about', []];
}
示例4: parseRequest
/**
* @param \yii\web\UrlManager $manager
* @param \yii\web\Request $request
* @return array|bool
*/
public function parseRequest($manager, $request)
{
if ($this->mode === self::CREATION_ONLY) {
return false;
}
if (!empty($this->verb) && !in_array($request->getMethod(), $this->verb, true)) {
return false;
}
$pathInfo = $request->getPathInfo();
if ($this->host !== null) {
$pathInfo = strtolower($request->getHostInfo()) . ($pathInfo === '' ? '' : '/' . $pathInfo);
}
$params = $request->getQueryParams();
$suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
$treeNode = null;
$originalDir = $pathInfo;
if ($suffix) {
$originalDir = substr($pathInfo, 0, strlen($pathInfo) - strlen($suffix));
}
$dependency = new TagDependency(['tags' => [(new Tree())->getTableCacheTag()]]);
if (!$pathInfo) {
$treeNode = Tree::getDb()->cache(function ($db) {
return Tree::find()->where(["site_code" => \Yii::$app->cms->site->code, "level" => 0])->one();
}, null, $dependency);
} else {
$treeNode = Tree::find()->where(["dir" => $originalDir, "site_code" => \Yii::$app->cms->site->code])->one();
}
if ($treeNode) {
\Yii::$app->cms->setCurrentTree($treeNode);
$params['id'] = $treeNode->id;
return ['cms/tree/view', $params];
} else {
return false;
}
}
示例5: getFormat
/**
* 获取响应的格式
* @return string
*/
protected function getFormat()
{
if ('' != ($extension = pathinfo($this->request->getPathInfo(), PATHINFO_EXTENSION))) {
$this->format = strtolower($extension);
}
return $this->format == '' ? 'html' : $this->format;
}
示例6: parseRequest
/**
* Parses the URL and sets the language accordingly
* @param \yii\web\Request $request
* @return array|bool
*/
public function parseRequest($request)
{
if ($this->enablePrettyUrl) {
$pathInfo = $request->getPathInfo();
$language = explode('/', $pathInfo)[0];
$locale = ArrayHelper::getValue($this->aliases, $language, $language);
if (in_array($language, $this->languages)) {
$request->setPathInfo(substr_replace($pathInfo, '', 0, strlen($language) + 1));
Yii::$app->language = $locale;
static::$currentLanguage = $language;
}
} else {
$params = $request->getQueryParams();
$route = isset($params[$this->routeParam]) ? $params[$this->routeParam] : '';
if (is_array($route)) {
$route = '';
}
$language = explode('/', $route)[0];
$locale = ArrayHelper::getValue($this->aliases, $language, $language);
if (in_array($language, $this->languages)) {
$route = substr_replace($route, '', 0, strlen($language) + 1);
$params[$this->routeParam] = $route;
$request->setQueryParams($params);
Yii::$app->language = $locale;
static::$currentLanguage = $language;
}
}
return parent::parseRequest($request);
}
示例7: parseRequest
/**
*
* @param \yii\web\UrlManager $manager
* @param \yii\web\Request $request
* @return array|bool
*/
public function parseRequest($manager, $request)
{
$rule = $this->getRuleByPattern($request->getPathInfo(), null);
if ($rule) {
$params = [];
parse_str($rule->defaults, $params);
return [$rule->route, $params];
}
return false;
}
示例8: getPathInfo
public function getPathInfo()
{
// Добавить кэш $pathInfo (не забыть про setPathInfo)
$pathInfo = parent::getPathInfo();
$pattern = Languages::all()->pattern();
if (preg_match("/^({$pattern})\\/(.*)/", $pathInfo, $arr)) {
$this->lang_url = $arr[1];
$pathInfo = $arr[count($arr) - 1];
}
return $pathInfo;
}
示例9: getRouteFromSlug
/**
* @param \yii\web\Request $request
* @return string
*/
public function getRouteFromSlug($request)
{
$_route = $request->getPathInfo();
$_params = $request->get();
$dbRoute = $this->getRouteFromCacheOrWriteCacheThenRead($_route, $_params);
if (is_object($dbRoute) && $dbRoute->hasAttribute('redirect')) {
if ($dbRoute->getAttribute('redirect')) {
Yii::$app->response->redirect([$dbRoute->slug], $dbRoute->getAttribute('redirect_code'));
}
}
return $_route;
}
示例10: parseRequest
/**
* Parse request
*
* @param \yii\web\UrlManager $manager
* @param \yii\web\Request $request
*
* @return array|bool
*/
public function parseRequest($manager, $request)
{
$pathInfo = $request->getPathInfo();
$url = preg_replace('#/$#', '', $pathInfo);
$page = (new CmsModel())->findPage($url);
if (!empty($page)) {
$params['pageAlias'] = $url;
$params['pageId'] = $page->id;
return [$this->route, $params];
}
return parent::parseRequest($manager, $request);
}
示例11: parseRequest
/**
* Parses the given request and returns the corresponding route and parameters.
* @param UrlManager $manager the URL manager
* @param Request $request the request component
* @return array|boolean the parsing result. The route and the parameters are returned as an array.
* If false, it means this rule cannot be used to parse this path info.
*/
public function parseRequest($manager, $request)
{
// If it's base url - call main page
if ($request->getPathInfo() === '') {
$mainPage = $this->getMainPage();
if ($mainPage !== false) {
Singleton::setData('content_template_id', $mainPage['content_template_id']);
if ($mainPage['type'] == ContentPage::TYPE_TEXT) {
return ['/content/default/view', ['slug' => $mainPage['slug']]];
} elseif ($mainPage['type'] == ContentPage::TYPE_INTERNAL_LINK) {
return ['/' . ltrim($mainPage['slug'], '/'), []];
}
}
}
$path = rtrim($request->getPathInfo(), '/');
$parts = explode('/', $path);
$languagePart = null;
// Multilingual support - remove language from parts
if (isset(Yii::$app->params['mlConfig']['languages'])) {
if (array_key_exists($parts[0], Yii::$app->params['mlConfig']['languages'])) {
$languagePart = array_shift($parts);
}
}
$slug = count($parts) == 1 && $parts[0] != '' ? $parts[0] : end($parts);
if (isset($this->getAllPages()[$slug])) {
if (isset($this->getAllPages()[$slug])) {
$page = $this->getAllPages()[$slug];
Singleton::setData('content_template_id', $page['content_template_id']);
return ['content/default/view', ['slug' => $slug, '_language' => $languagePart]];
}
} elseif (count($parts) > 1) {
$slug = implode('/', $parts);
if (isset($this->getAllPages()[$slug])) {
$page = $this->getAllPages()[$slug];
Singleton::setData('content_template_id', $page['content_template_id']);
}
}
return false;
// this rule does not apply
}
示例12: parseRequest
/**
* Parses the given request and returns the corresponding route and parameters.
* @param \yii\web\UrlManager $manager the URL manager
* @param \yii\web\Request $request the request component
* @return array|boolean the parsing result. The route and the parameters are returned as an array.
* If false, it means this rule cannot be used to parse this path info.
*/
public function parseRequest($manager, $request)
{
$this->initPatrones();
$pathInfo = $request->getPathInfo();
//vendedor
if ($this->verificaRuta($this->patrones[self::P_VENDEDOR], $pathInfo)) {
$parametros = $this->obtenerParametros($this->patrones[self::P_VENDEDOR], $pathInfo);
return [$this->ruta[self::P_VENDEDOR], $parametros];
}
//profesional
if ($this->verificaRuta($this->patrones[self::P_PROFESIONAL], $pathInfo)) {
$parametros = $this->obtenerParametros($this->patrones[self::P_PROFESIONAL], $pathInfo);
return [$this->ruta[self::P_PROFESIONAL], $parametros];
}
//categoria
if ($this->verificaRuta($this->patrones[self::P_CATEGORIAS], $pathInfo)) {
$parametros = $this->obtenerParametros($this->patrones[self::P_CATEGORIAS], $pathInfo);
// echo '<pre>';print_r([__LINE__, __METHOD__,$pathInfo,$this->patrones[self::P_CATEGORIAS]]);die();
//registrar click
// if(Yii::$app->request->getBodyParam('hc') == 7 ){
// Yii::$app->visitas->registrarClick($parametros['categoria'], 'C');
// }
//registro de impresion de la categoria
// Yii::$app->visitas->registrarImpresion($parametros['categoria'], 'C');
return [$this->ruta[self::P_CATEGORIAS], $parametros];
}
//categoria-provincia
if ($this->verificaRuta($this->patrones[self::P_CATEGORIA_PROVINCIA], $pathInfo)) {
$parametros = $this->obtenerParametros($this->patrones[self::P_CATEGORIA_PROVINCIA], $pathInfo);
//registro de impresion de la categoria
return [$this->ruta[self::P_CATEGORIA_PROVINCIA], $parametros];
}
//detalle articulo
//municipio/articulo
if ($this->verificaRuta($this->patrones[self::P_MUNICIPIO_DESCUENTO], $pathInfo)) {
$parametros = $this->obtenerParametros($this->patrones[self::P_MUNICIPIO_DESCUENTO], $pathInfo);
//registrar click
// if(Yii::$app->request->getBodyParam('hc') == 7 ){
// Yii::$app->visitas->registrarClick($parametros['articulo'], 'A');
// }
//registro de impresion de la categoria
// Yii::$app->visitas->registrarImpresion($parametros['articulo'], 'A');
return [$this->ruta[self::P_MUNICIPIO_DESCUENTO], $parametros];
}
//provincia
if ($this->verificaRuta($this->patrones[self::P_PROVINCIA], $pathInfo)) {
$parametros = $this->obtenerParametros($this->patrones[self::P_PROVINCIA], $pathInfo);
return [$this->ruta[self::P_PROVINCIA], $parametros];
}
return false;
}
示例13: parseRequest
/**
* @param \yii\web\UrlManager $manager
* @param \yii\web\Request $request
* @return array|bool
*/
public function parseRequest($manager, $request)
{
$pathInfo = $request->getPathInfo();
$params = $request->getQueryParams();
$sourceOriginalFile = File::object($pathInfo);
$extension = $sourceOriginalFile->getExtension();
if (!$extension) {
return false;
}
if (!in_array(StringHelper::strtolower($extension), (array) \Yii::$app->imaging->extensions)) {
return false;
}
return ['cms/imaging/process', $params];
}
示例14: parseRequest
/**
* @param \yii\web\UrlManager $manager
* @param \yii\web\Request $request
* @return array|bool
*/
public function parseRequest($manager, $request)
{
$pathInfo = $request->getPathInfo();
$params = $request->getQueryParams();
$sourceOriginalFile = File::object($pathInfo);
$extension = $sourceOriginalFile->getExtension();
if (!$extension) {
return false;
}
if (Validate::validate(new AllowExtension(), $extension)->isInvalid()) {
return false;
}
return ['cms/imaging/process', $params];
}
示例15: redirectToLanguage
/**
* Redirect to the current URL with given language code applied
*
* @param string $language the language code to add. Can also be empty to not add any language code.
*/
protected function redirectToLanguage($language)
{
// Examples:
// 1) /baseurl/index.php/some/page?q=foo
// 2) /baseurl/some/page?q=foo
// 3)
// 4) /some/page?q=foo
if ($this->showScriptName) {
// 1) /baseurl/index.php
// 2) /baseurl/index.php
// 3) /index.php
// 4) /index.php
$redirectUrl = $this->_request->getScriptUrl();
} else {
// 1) /baseurl
// 2) /baseurl
// 3)
// 4)
$redirectUrl = $this->_request->getBaseUrl();
}
if ($language) {
$redirectUrl .= '/' . $language;
}
// 1) some/page
// 2) some/page
// 3)
// 4) some/page
$pathInfo = $this->_request->getPathInfo();
if ($pathInfo) {
$redirectUrl .= '/' . $pathInfo;
}
if ($redirectUrl === '') {
$redirectUrl = '/';
}
// 1) q=foo
// 2) q=foo
// 3)
// 4) q=foo
$queryString = $this->_request->getQueryString();
if ($queryString) {
$redirectUrl .= '?' . $queryString;
}
Yii::$app->getResponse()->redirect($redirectUrl);
if (YII_ENV_TEST) {
throw new \yii\base\Exception(\yii\helpers\Url::to($redirectUrl));
} else {
Yii::$app->end();
}
}