當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Request::resolve方法代碼示例

本文整理匯總了PHP中yii\web\Request::resolve方法的典型用法代碼示例。如果您正苦於以下問題:PHP Request::resolve方法的具體用法?PHP Request::resolve怎麽用?PHP Request::resolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\web\Request的用法示例。


在下文中一共展示了Request::resolve方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: handleRequest

 /**
  * Handles the specified request.
  * @param Request $request the request to be handled
  * @return Response the resulting response
  * @throws NotFoundHttpException if the requested route is invalid
  */
 public function handleRequest($request)
 {
     if (empty($this->catchAll)) {
         list($route, $params) = $request->resolve();
     } else {
         $route = $this->catchAll[0];
         $params = $this->catchAll;
         unset($params[0]);
     }
     try {
         Yii::trace("Route requested: '{$route}'", __METHOD__);
         $this->requestedRoute = $route;
         $result = $this->runAction($route, $params);
         if ($result instanceof Response) {
             return $result;
         } else {
             $response = $this->getResponse();
             if ($result !== null) {
                 $response->data = $result;
             }
             return $response;
         }
     } catch (InvalidRouteException $e) {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'), $e->getCode(), $e);
     }
 }
開發者ID:hakudjin,項目名稱:yii2,代碼行數:32,代碼來源:Application.php

示例2: resolve

 /**
  * Resolve
  * Resolves the current request into a route and the associated parameters.
  * Sets default application language
  * @return array the first element is the route, and the second is the associated parameters.
  * @throws \yii\web\NotFoundHttpException if the request cannot be resolved.
  */
 public function resolve()
 {
     $resolve = parent::resolve();
     $languages = Language::getDb()->cache(function ($db) {
         return Language::find()->where(['is_active' => true])->asArray()->all();
     });
     Yii::$app->params['languages'] = ArrayHelper::map($languages, 'code', 'code');
     Yii::$app->language = $this->getCurrentLang();
     return $resolve;
 }
開發者ID:jarrus90,項目名稱:yii2-multilang,代碼行數:17,代碼來源:MultilangRequest.php

示例3: handleRequest

 /**
  * Handles the specified request.
  * @param Request $request the request to be handled
  * @return Response the resulting response
  * @throws NotFoundHttpException if the requested route is invalid
  */
 public function handleRequest($request)
 {
     if (empty($this->catchAll)) {
         try {
             list($route, $params) = $request->resolve();
         } catch (UrlNormalizerRedirectException $e) {
             $url = $e->url;
             if (is_array($url)) {
                 if (isset($url[0])) {
                     // ensure the route is absolute
                     $url[0] = '/' . ltrim($url[0], '/');
                 }
                 $url += $request->getQueryParams();
             }
             return $this->getResponse()->redirect(Url::to($url, $e->scheme), $e->statusCode);
         }
     } else {
         $route = $this->catchAll[0];
         $params = $this->catchAll;
         unset($params[0]);
     }
     try {
         Yii::trace("Route requested: '{$route}'", __METHOD__);
         $this->requestedRoute = $route;
         $result = $this->runAction($route, $params);
         if ($result instanceof Response) {
             return $result;
         } else {
             $response = $this->getResponse();
             if ($result !== null) {
                 $response->data = $result;
             }
             return $response;
         }
     } catch (InvalidRouteException $e) {
         throw new NotFoundHttpException(Yii::t('yii', 'Page not found.'), $e->getCode(), $e);
     }
 }
開發者ID:Abbas-Hashemian,項目名稱:yii2,代碼行數:44,代碼來源:Application.php

示例4: testResolve

    public function testResolve()
    {
        $this->mockWebApplication([
            'components' => [
                'urlManager' => [
                    'enablePrettyUrl' => true,
                    'showScriptName' => false,
                    'cache' => null,
                    'rules' => [
                        'posts' => 'post/list',
                        'post/<id>' => 'post/view',
                    ],
                ]
            ]
        ]);

        $request = new Request();
        $request->pathInfo = 'posts';

        $_GET['page'] = 1;
        $result = $request->resolve();
        $this->assertEquals(['post/list', ['page' => 1]], $result);
        $this->assertEquals($_GET, ['page' => 1]);

        $request->setQueryParams(['page' => 5]);
        $result = $request->resolve();
        $this->assertEquals(['post/list', ['page' => 5]], $result);
        $this->assertEquals($_GET, ['page' => 1]);

        $request->setQueryParams(['custom-page' => 5]);
        $result = $request->resolve();
        $this->assertEquals(['post/list', ['custom-page' => 5]], $result);
        $this->assertEquals($_GET, ['page' => 1]);

        unset($_GET['page']);

        $request = new Request();
        $request->pathInfo = 'post/21';

        $this->assertEquals($_GET, []);
        $result = $request->resolve();
        $this->assertEquals(['post/view', ['id' => 21]], $result);
        $this->assertEquals($_GET, ['id' => 21]);

        $_GET['id'] = 42;
        $result = $request->resolve();
        $this->assertEquals(['post/view', ['id' => 21]], $result);
        $this->assertEquals($_GET, ['id' => 21]);

        $_GET['id'] = 63;
        $request->setQueryParams(['token' => 'secret']);
        $result = $request->resolve();
        $this->assertEquals(['post/view', ['id' => 21, 'token' => 'secret']], $result);
        $this->assertEquals($_GET, ['id' => 63]);
    }
開發者ID:nxnx,項目名稱:yii2,代碼行數:55,代碼來源:RequestTest.php


注:本文中的yii\web\Request::resolve方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。