0

www.foo.com/blog/posts/view/12/12/2013

没有可能的文件对应于这个请求。所以这个 URL 需要通过一些逻辑来解析,否则你会得到一个 404。

由于没有对应的文件,服务器无法自动响应。我只是想知道 Cake FIRST 的哪一部分会响应这样的请求。我了解简单的页面请求首先由路由器解析和解析。但是 URL 不能神奇地到达路由器的前门,对吧?我真的很想知道将 URL 带到路由器的幕后发生了什么。

4

1 回答 1

1

检查你的 app/webroot/index.php,底部:

$Dispatcher = new Dispatcher();
$Dispatcher->dispatch(
    new CakeRequest(),
    new CakeResponse()
);

Dispatcher 的关键方法是 parseParams。该方法在 Dispatcher::dispatch() 开始时通过事件系统触发,在类中也检查该方法。

发生的情况基本上是调度程序使用路由器解析纯url并将其转换为参数并将解析结果添加到请求对象,然后根据解析结果调度控制器。

/**
 * Applies Routing and additionalParameters to the request to be dispatched.
 * If Routes have not been loaded they will be loaded, and app/Config/routes.php will be run.
 *
 * @param CakeEvent $event containing the request, response and additional params
 * @return void
 */
        public function parseParams($event) {
                $request = $event->data['request'];
                Router::setRequestInfo($request);
                $params = Router::parse($request->url);
                $request->addParams($params);

                if (!empty($event->data['additionalParams'])) {
                        $request->addParams($event->data['additionalParams']);
                }
        }
于 2013-12-12T02:40:43.980 回答