dongyuedaochen8415 2016-02-28 11:03
浏览 67
已采纳

在请求 - 响应过程中,当运行Yii -2.0应用程序时,幕后的内容是什么?

I'm trying to make a simplest and a very basic request-response system in php, similar to as in Yii-2.0. For that I was reading inside the basic\web\index.php there is:

$application = new yii\web\Application($config);
$application->run();

I dug deeper, but couldn't figure out how the process is carried out.

Here is what I found:

the run() method in yii\web\application has this (excluding the triggers):

$response = $this->handleRequest($this->getRequest());
$response->send();
return $response->exitStatus;

handleRequest is just an abstract function yet,

abstract public function handleRequest($request);

So I basically don't understand how this code is returning a response?

UPDATE:

As answered here is the handleRequest function for quick referene:

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);
        }
    }

i'm in a process to figure out the whole process. will post as an answer as soon as I get a full hold of it. Probably we shall make a better flowchart than Yii documentation. :)

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大