Copy CodeThe code is as follows:
Assume that the configuration for Urlmanager is configured for path mode, with the YII default configuration:
Copy CodeThe code is as follows:
' Urlmanager ' =>array (
' Urlformat ' = ' path ',
' Rules ' =>array (
' / ' = ' /view ',
' // ' = ' /',
' /' = ' /',
),
),
What kind of link address does the above two lines of code produce?
/HTTP /user/register//Error link
/HTTP /index.php/user/register//correct link
The first link is wrong, and the browser returns a 404 error. The second link accesses the Usercontroller's Register method. The difference is that the second link is generated when we pass in an array of parameters, and the first method is a simple string. Yii when processing a URL, it encounters a simple string that uses the string as the final URL, and when an array is encountered, it calls the controller's createurl to generate the URL.
When it comes to simple strings, there's actually a very real difference between the two links. Although the same is the string ' User/register ', but in the first string represents a 13-character relative path, and the second link represents the Usercontroller registeraction, is a special meaning.
Attach the source code of the method normalizeurl that Yii handles the URL:
Copy CodeThe code is as follows:
/**
* normalizes the input parameter to be a valid URL.
*
* If The input parameter is an empty string, the currently requested URL would be returned.
*
* If The input parameter is a non-empty string, it is treated as a valid URL and would
* be returned without any change.
*
* If The input parameter is an array, it is treated as a controller route and a list of
* GET parameters, and the {@link Ccontroller::createurl} method is invoked to
* Create a URL. The first array element refers to the controller route,
* and the rest Key-value pairs refer to the additional GET parameters for the URL.
* For example,
array('post/list', 'page'=>3)May is used to generate the URL
*
/index.php?r=post/list&page=3.
*
* @param mixed $url The parameter to being used to generate a valid URL
* @return string The normalized URL
*/
public static function Normalizeurl ($url)
{
if (Is_array ($url))
{
if (isset ($url [0]))
{
if ($c =yii::app ()->getcontroller ())!==null)
$url = $c->createurl ($url [0],array_splice ($url, 1));
Else
$url =yii::app ()->createurl ($url [0],array_splice ($url, 1));
}
Else
$url = ";
}
return $url = = = "? Yii::app ()->getrequest ()->geturl (): $url;
}
http://www.bkjia.com/PHPjc/324933.html www.bkjia.com true http://www.bkjia.com/PHPjc/324933.html techarticle Copy the code as follows: PHP echo chtml::link (' Error link ', ' user/register ')?? PHP echo chtml::link (' Correct link ', Array (' User/register '))? Assume that the Urlmanager configuration is set to ...