本文整理汇总了PHP中yii\web\Request::getUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getUrl方法的具体用法?PHP Request::getUrl怎么用?PHP Request::getUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\web\Request
的用法示例。
在下文中一共展示了Request::getUrl方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUrl
public function getUrl()
{
if ($this->langUrl === null) {
$this->langUrl = parent::getUrl();
$this->originalUrl = $this->langUrl = parent::getUrl();
$scriptName = '';
if (strpos($this->langUrl, $_SERVER['SCRIPT_NAME']) !== false) {
$scriptName = $_SERVER['SCRIPT_NAME'];
$this->langUrl = substr($this->langUrl, strlen($scriptName));
}
Yii::$app->getModule('radiata')->getActiveLanguageByUrl($this->langUrl);
if (Yii::$app->getModule('radiata')->activeLanguage->code) {
Yii::$app->language = Yii::$app->getModule('radiata')->activeLanguage->locale;
if (Yii::$app->getModule('radiata')->activeLanguage->code != Yii::$app->getModule('radiata')->defaultLanguage->code) {
$this->langUrl = substr($this->langUrl, strlen(Yii::$app->getModule('radiata')->activeLanguage->code) + 1);
}
}
if (!$this->langUrl) {
$this->langUrl = $scriptName . '/';
}
} else {
$this->langUrl = parent::getUrl();
}
return $this->langUrl;
}
示例2: validateParams
/**
* @param \yii\web\Request $request
* @return bool
*/
public function validateParams(Request $request)
{
if ($this->signKey !== null) {
$httpSignature = $this->getHttpSignature();
$path = urldecode(parse_url($request->getUrl(), PHP_URL_PATH));
parse_str(parse_url($request->getUrl(), PHP_URL_QUERY), $urlParams);
if (isset($urlParams['_'])) {
unset($urlParams['_']);
}
try {
$httpSignature->validateRequest($path, $urlParams);
} catch (SignatureException $e) {
return false;
}
}
return true;
}
示例3: handleRedirectRequest
/**
* @param \yii\web\Request $request
* @return \yii\web\Response|null
*/
protected function handleRedirectRequest($request)
{
$key = ltrim(str_replace($request->getBaseUrl(), '', $request->getUrl()), '/');
if (array_key_exists($key, $this->redirectRoutes)) {
return $this->getResponse()->redirect(Url::to($this->redirectRoutes[$key]));
} else {
return null;
}
}
示例4: 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', []];
}
示例5: parseRequest
/**
* Parses the given request and returns the corresponding route and parameters.
* @param \yii\web\UrlManager $manager the URL manager
* @param Request $request the request component
* @return array|bool the parsing result. The route and the parameters are returned as an array.
* @throws ForbiddenHttpException
*/
public function parseRequest($manager, $request)
{
if (!($pathInfo = $request->getPathInfo() or $pathInfo = $this->getMenuMap()->getMainPagePath())) {
return false;
}
//Пункт 2
$this->_activeMenuIds = array_keys($this->getMenuMap()->getLinks(), $request->getUrl());
if ($this->_menu = $this->getMenuMap()->getMenuByPath($pathInfo)) {
//Пункт 1.1
$this->_activeMenuIds[] = $this->_menu->id;
$this->_menu->setContext(MenuItem::CONTEXT_PROPER);
//при полном совпадении метаданные меню перекрывают метаднные контроллера
Yii::$app->getView()->on(View::EVENT_BEGIN_PAGE, [$this, 'applyMetaData']);
} elseif ($this->_menu = $this->getMenuMap()->getApplicableMenuByPath($pathInfo)) {
//Пункт 1.2
$this->_activeMenuIds[] = $this->_menu->id;
$this->_menu->setContext(MenuItem::CONTEXT_APPLICABLE);
$this->applyMetaData();
} else {
return false;
}
// устанавливаем макет приложению
Event::on(Controller::className(), Controller::EVENT_BEFORE_ACTION, [$this, 'applyLayout']);
//Проверка на доступ к пунтку меню
if (!empty($this->_menu->access_rule) && !Yii::$app->user->can($this->_menu->access_rule)) {
if (Yii::$app->user->getIsGuest()) {
Yii::$app->user->loginRequired();
} else {
throw new ForbiddenHttpException(Yii::t('gromver.platform', 'You have no rights for access to this section of the site.'));
}
}
if ($this->_menu->getContext() === MenuItem::CONTEXT_PROPER) {
return $this->_menu->parseUrl();
} else {
$requestRoute = substr($pathInfo, mb_strlen($this->_menu->path) + 1);
list($menuRoute, $menuParams) = $this->_menu->parseUrl();
$requestInfo = new MenuRequest(['menuMap' => $this->getMenuMap(), 'menuRoute' => $menuRoute, 'menuParams' => $menuParams, 'requestRoute' => $requestRoute, 'requestParams' => $request->getQueryParams()]);
foreach ($this->_parseUrlRules as $rule) {
if ($result = $rule->process($requestInfo, $this)) {
return $result;
}
}
return false;
}
}
示例6: Request
use yii\helpers\ArrayHelper;
use yii\helpers\FileHelper;
use yii\web\Request;
require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
require __DIR__ . '/../../common/config/bootstrap.php';
$config = yii\helpers\ArrayHelper::merge(require __DIR__ . '/../../common/config/main.php', require __DIR__ . '/../../common/config/main-local.php');
$request = new Request();
$request->init();
$imageCacheConfig = $config['components']['imageCache'];
/**
* @var maddoger\imagecache\ImageCache $imageCache
*/
$imageCache = Yii::createObject($imageCacheConfig);
$cachedUrl = $request->getUrl();
$preg = '/^' . preg_quote(Yii::getAlias($imageCache->cacheUrl), '/') . '\\/(.*?)\\/(.*?)\\.(.*?)$/';
if (preg_match($preg, $cachedUrl, $matches)) {
$presetName = $matches[1];
if (!$imageCache->hasPreset($presetName)) {
header('HTTP/1.0 400 Bad Request');
exit('Preset not found.');
}
$imagePath = Yii::getAlias($imageCache->staticPath . DIRECTORY_SEPARATOR . $matches[2] . '.' . $matches[3]);
$format = strtolower($matches[3]);
if (file_exists($imagePath)) {
try {
$image = $imageCache->getImage($imagePath, $presetName);
if ($image && $image->isValid()) {
$preset = $imageCache->presets[$presetName];
$saveOptions = ArrayHelper::merge($imageCache->saveOptions, ArrayHelper::remove($preset, 'save', []));