I’m fairly new to Yii and I’m running into the following issue within the URLManager.
I want to have Yii check if a controller exists, and if not, use the default one.
For example:
I create the pages about, contact and life. Those I want to be able to access through mysite/about, mysite/contact and mysite/life.
If I only had these kind of pages, I could use the rule:
‘<action:\w+>’ => ‘site/<action>’
Site being the defualt controller.
But if I then access, lets say, users, which has its own controller, it should use the controller Users when I access mysite/Users.
What is the way for this in Yii? Is there a ‘default’ option to realise such thing without adding all those paging as a rule (which slows down the application)?
That’s not really what I want to achieve. What I want is this:
let’s say we have 2 controllers, cms, for the main cms content. And the controllers users.
If you go to www.example.com you will get the main controller, in this case cms, thats good. If you go to www.example.com/users/view you get the users controller. But, and here is the tricky part, lets say we have a contact page in the controller cms you would have to go to www.example.com/cms/contact. But thats not what I want. I wanna go to www.example.com/contact and the URLmanager should check if controller contact exists, if not, use the default controller, cms and view the contact page because contact wasn’t a controller so it’s a view. so the first string after the url could be a controller name or a view if controller doesn’t exists.
I hope you understand what I want to achieve here :roll eyes:
Ah, I see now what you did here. I tested this but it didn’t work. After I wrote the text above this one I changed some things in your code and it works fine now!:
'<action:[\w\-]+>.html' => 'site/<action>',
You could even delete the .html part, works too if you don’t want the .html in your url.