当前位置: 首页>>代码示例>>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;未经允许,请勿转载。