Create URL in Yii with element name with # [closed

2019-06-17 04:52发布

问题:

I need to create URLs in Yii with specifying a div on the page to focus when clicked... I know I need to put the div name with # in the URL, but how do I specify that in createUrl function of Yii...

The createUrl() function only provides options for parameters, not for elements...as per my knowledge.

回答1:

If you check createUrl:

additional GET parameters (name=>value). Both the name and value will be URL-encoded. If the name is '#', the corresponding value will be treated as an anchor and will be appended at the end of the URL.

You can add it like this:

 echo $this->createUrl('controller/action',array('#'=>'name'));