Yii Create URL (i)

Source: Internet
Author: User
Tags yii

1. $this->redirect The $this here is the current controller. It could be the application, or it could be the module. Only the first parameter is the URL, and when the URL is a string, it will jump itself like $this->redirect ('/'); Will jump to the site root, if your current host is localhost,
Then he jumps to http://localhost/, and then $this->redirect ('/books '), and jumps to http://localhost/books in the application's controller or using the $ This->redirect (' books '); it jumps to http://localhost/books. But when you use this in the module, there is another case,
When you open Urlmanager and set up a hidden script file, enter if your current access address is http://localhost/admin/default/index when using $this->redirect (' books '); Jump, jump after the address is http://localhost/admin/default/books here just to say, redirect simple jump, I personally suggest, if not jump to other items, or outbound $this->redirect (' Http://yiibook.com '), it is recommended to use the following method

URLs use arrays when the URL is an array, the Urlmanager is called to route the path to the organization of the jump, which is ideal and is based on the routing
Changes if there is a route for ' book ' = ' admin/default/index ' format: ' route ' = ' = ' real address ', which specifies the access It is equivalent to the index operation method of the default controller under the admin model of the square. Since the use of routing, mainly to make the URL more friendly, and hide the real address then, when you want to use $this->redirect to jump to this route, you need to specify the real address, such as $this->redirect (Array (' admin/ Default/index '); This will jump to this address, and the URL display is really book, and when you build roads by name, such as ' books ' = ' admin/default/index ', or simply remove this path, Do not modify your program in the case of the module, if you are currently in the Admin module controller, use jump, you can not write ModuleID directly using $this->redirect (Array (' Default/index ')); It's ok too, so your module won't
Depends on ModuleID again if you are currently also in the default controller under the Admin module, you can also use the
$this->redirect (Array (' index ')); jump, do not rely on the name of the controller we'll take a look at the route with parameters ' book<id:\d+> ' = ' admin/default/index ' Then , the URL needs to pass a parameter ID for this path, such as $this->redirect (' Admin/default/index ', ' id ' =>1), and the URL format is array (' Real path ', ' parameter name ' = = ' Argument value ', ' parameter name 2 ' = ' = ' parameter value 2 ', ....); Many components or methods in Yii have a format that supports such URLs, such as CMenu, and so on. 2.CREATEURL, with $this->createurl and Yii::app ()->createurl,createurl it will be organized into a routing format based on the actual address, based on the route above, creating url$this-> CreateURL (' Admin/default/index ') with parameter case $this->createurl (' Admin/default/index ', array (' ID ' =>1) '), admin module, using $ This->createurl (' Default/index '); or $this->create (' index '); Do not use Yii::app ()->createurl, Avoid relying on specific routes note the difference between the redirect and CreateURL parameters.

Yii Create URL (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.