Home  >  Article  >  Backend Development  >  Yii framework URL parsing problem_PHP tutorial

Yii framework URL parsing problem_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:19:22778browse

First of all, if you do not configure urlManager in config/main.php, then the process is as follows (taken from yii official website)

The user makes a request to access the URL http://www.example.com/index.php?r=post/show&id=1, and the web server processes this request by executing the entry script index.php.
The entry script creates an application instance and executes it.
The application obtains the details of the user's request from an application component called request.
The application determines the requested controller and action with the help of an application component called urlManager. In this example, the controller is post, which represents the PostController class; the action is show, whose actual meaning is determined by the controller.
The application creates an instance of the requested controller to further handle the user request. The controller determines that the action show points to a method named actionShow in the controller class. It then creates and maintains filters associated with the action (e.g. access control, benchmarking). If allowed by the filter, the action will be executed.
The action reads a Post model with ID 1 from the database.
The action renders a view named show through the Post model.
The view reads and displays the properties of the Post model.
The view performs some widgets.
The rendering result of the view is inserted into a layout.
The action completes rendering of the view and presents it to the user.
But if you have configured urlManager as follows:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
                    '/'=>'/index',
                       '/'=>'/',
                  '//'=>'/',
),
),
Then it is impossible to get the result of show action by directly accessing http://www.example.com/index.php?r=post/show&id=1. First, this request will be handed over to the indexAction of defaultController for processing. DefaultController is specified in main.php. If defaultController is not PostControler, you may be confused. If it happens to be, the content of indexAction will be returned instead of showAction.
In fact, accessing this is very simple, just http://www.example.com/index.php/post/show?id=1
Because the urlManager has been set up in the form of /

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532691.htmlTechArticleFirst of all, if you do not configure urlManager in config/main.php, then the process is as follows (taken from yii official website) User Issued the access URL http://www.example.com/index.php?r=post/showi...
Statement:
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