Home > php教程 > php手册 > body text

yii框架网址解析问题

WBOY
Release: 2016-06-21 08:49:05
Original
1091 people have browsed it

首先如果你在config/main.php里面没有配置urlManager的话,那么流程如下(摘自yii官网)

用户发出了访问 URL http://www.example.com/index.php?r=post/show&id=1 的请求,Web 服务器通过执行入口脚本index.php 处理此请求。

入口脚本创建了一个 应用 实例并执行。

应用从一个叫做 request 的 应用组件中获得了用户请求的详细信息。

应用在一个名叫 urlManager 的应用组件的帮助下,决定请求的 控制器和 动作 。在这个例子中,控制器是 post,它代表 PostController 类;动作是 show ,其实际含义由控制器决定。

应用创建了一个所请求控制器的实例以进一步处理用户请求。控制器决定了动作show 指向控制器类中的一个名为 actionShow 的方法。然后它创建并持行了与动作关联的过滤器(例如访问控制,基准测试)。如果过滤器允许,动作将被执行。

动作从数据库中读取一个 ID 为 1 的 Post 模型。

动作通过 Post 模型渲染一个名为 show 的 视图。

视图读取并显示 Post 模型的属性。

视图执行一些 小物件。

视图的渲染结果被插入一个 布局。

动作完成视图渲染并将其呈现给用户。

但是如果你已经配置了urlManager如下:

'urlManager'=>array(

            'urlFormat'=>'path',

            'rules'=>array(

                '/'=>'/index',

                '/'=>'/',

                '//'=>'/',

            ),

        ),

那么直接访问http://www.example.com/index.php?r=post/show&id=1就不可能得到show action的结果了。首先这个请求会交给defaultController的indexAction处理,defaultController在main.php里制定,如果defaultController不是PostControler,你可能就会莫名其妙了。如果正好是的话,则会返回indexAction的内容,而不是showAction。

其实要访问这个也很简单,http://www.example.com/index.php/post/show?id=1就行了

因为urlManager已经设置成按照/的形式

 



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!