Say something about Yii's Yii::app ()->createurl and Chtml::normalizeurl use problems

Source: Internet
Author: User

Now for the next question, take a look at the following code:

$words = Array (), foreach ($items as $item) {$tmp [' link '] = chtml::link ($item [' Searchword '], Chtml::normalizeurl (' List/search ', ' name ' = UrlEncode ($item [' Searchword ')))); $words [] = $tmp; unset ($tmp);}

This is me again in the search project which has the problem, found a problem, is a popular search, will list 5 frequently searched questions of course, this function is placed on the head, the page has loaded this header file,

When I click on the first page of these popular search products, it is normal to jump to the corresponding pages, but if I click on a product, such as: Apple, then we jump to the Apple product of the detailed products,

The URL:HTTP://CLZV2.LYGCLZ.COM/INDEX.PHP/PRODUCT/DEFAULT/VIEW/PID/1 of Apple products

At this point, when we click on a popular search item, we get an error. URL does not exist,

URL of a popular product: Http://www.clz.com/index.php/product/list/search/name/%25E5%25BC%2580%25E5%25BF%2583%25E6%259E%259C

The reason for the error is that there is an extra product path in the/product/list. Get rid of the normal, the problem is that the code above the array (' List/search '), should be an array ('/list/search ').

If the list is not added before/, Yii will assume that it refers to the list under the product module, so you should pay attention to the details.


Yii::app ()->createurl

Public Function CreateURL ($route, $params =array (), $ampersand = ' & ') {return $this->geturlmanager () CreateURL ($route, $params, $ampersand);}

Chtml::normalizeurl

Normalizeurl () method public static string Normalizeurl (mixed $url) $url mixed generate a valid URL for the parameter {return} string valid URL Source: Framew ork/web/helpers/chtml.php#1088 (show) 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;} A valid URL is generated from the standard input. If the input parameter is an empty string, the URL of the current request is returned. If the input parameter is not an empty string, it is treated as a valid URL and is returned without any changes. If the input parameter is an array, it is treated as a controller route and a get parameter list, and the Ccontroller::createurl method is called to create a URL. In this case, the first element of the array refers to the routing of the Controller, and the other key-value pairs refer to the additional URL parameters. For example, an array (' post/list ', ' page ' =>3) can generate a url/index.php?r=post/list&page=3.


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.