简体   繁体   中英

Yii how to make controller action with replace string

How the best way to create action in the controller to be more user friendly??? I use it :

http://pastebin.com/AFiBVfRs

In every controller that I made I always put to be called from URL

Ex : www.domain.com/news/my-profile.html

With the help of the code I managed to make my page displayed properly, because the sign "-" will be replaced with "_" which made controller read the name of action.

But this method can't be used if I use a function to display the data from database .. For example: CActiveDataProvider. When I call the page always comes out error is:

Fatal error: Call to a member function getId () on a non-object in / home/z65111222/framework/yiilite.php on line 3860

Is there a better way to make my action could still be called using the sign "-" instead of "_"

I think all of what you want should be

custom url friendly class

If you have no idea about above class for what purpose, just read

http://www.yiiframework.com/doc/guide/1.1/en/topics.url#using-custom-url-rule-classes

Once you got the idea, and want to do more custom on your own, this link would help

Yii - Make a string usable in a URL or filename

At last, if you want the suffix .html , just add below line into urlMamanager (on your app config)

'urlSuffix'=> '.html',

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM