How To Setup Yii Frontend

As the title suggests.

Yi is a great framework I love it so far. I have worked on the backend of a cms and now want to go with the frontend.

The controller/action idea is great for using in the backend. The urls or modules don’t change.

But the frontend… I have been looking into this problem for about 2 weeks now.

If a user makes an page in the backend like; or

It should load dynamic text from a database table or a module. Usually we would redirects everything to index.php and send it to a main entry controller. And retrieve the GET parameters from there.

Also a module can be put under multiple pages. Or a page with a module have it’s name changed. Example, like user changes to

Any suggestions?

How have you guys set this up. I can’t find much info about this part. I can’t be the only one with this problem.

Please no replies with links to documentation. I just want an answer.

Sorry if this has been asked before couldn’t find it that quickly. And it very mystifying to me.

That is extremely rude!

It’s very clear to me that you haven’t spent any time at all reading any documentation, and you want a quick answer.

Good luck. :)

Frontend, backend?

There is no difference.

Should I copy and paste from the documentation? Or spend precious time coming up with something new and fresh? No, I don’t think so. ;)

Please, spend more time to think about exactly what it is you want to do, and put some effort into asking a better question.

Sorry if you are upset. Not sure why though. It was not my intention to be rude. Neither do I think I was. I was just asking a question.

I did read the Yii documentation. About Url Management for example. Have the say the documentation is very good. And Yii is a great framework. Just that I think a quick personal answer would be faster. But if you have documentation that is fine too. It’s just that I tried several things and didn’t work. Since projects can be different and thus people need different setups. What work for one doesn’t necessarily work for the other.

EDIT. Again I profoundly apologise for any miscommunication from my end. I did not have any ill intentions.

To explain my situation. I have a frontend and backend setup as described in the The directory structure of the Yii project site by Mr qiang. But I have also seen other setups that use an backend as an admin folder in the main application. That is what I meant with backend and frontend. I use the backend to create, edit and delete the specific modules.

The frontend then mostly renders the dynamic content and the modules that are connect to a page (if possible). To give an example. The user logins in to the backend. And creates several pages. For example a page called "home". This page has an url with "/home". Meaning it is located at

User goes to the frontend and types in and sees the text and if possible a module.

My question is related to this backend and frontend structure and idea. To come back to my question. The frontend uses the url manager that treats an url as an <controller>/<action> type. Thus treating the page "/home" as an controller or either module. How could I make it possible to transfer all frontend requests like "/home" or sublevels to go to one controller that handles them.

I hope it’s possible that someone can give me abit of advice.

Fair enough. :)

You can achieve this in a multitude of ways.

I think the easiest way is to use a page controller where each page has a regular id, a slug and a category associated with it.

You page controller has a loadModel function which loads the model by slug (instead of by id) and the url manager has a rule which tells it to route a request to something like this:


There is an extension called ‘SlugBehavior’ which can help you create slugs for your pages from titles, like in Wordpress.

Does this sound like something you can use?

Thanks for the reply.

I had noidea this was called a slug. It’s a new term for me. And I have been working with php for quite some time. It seems to be a reference for a clean url. I also made some other cms not in Yii though. I usually just put something like rewrite all to index.php in a htacesss. And then the controller will just use the current get name like ‘home’ and searches for a page associated with it. Based on the current name and parent. If a user has made two the same pages named ‘home’ with the same parent then it’s a duplicate and his/her own problem :D.

But to come back. I have currently managed to write the first levels meaning to a pageController that handles the request as follows. But it doesn’t work for Below is what I changed in the config of main.php






         '/'=>'/page/index', //write everything to the pageController


    // other rules


I used a / (frontslash) to do this. I am basically almost there just need the rest of the requests to go there as well. Forgive my curiousity but how does everyone else manage to link the pages in the backend to a frontendcontroller? Or are they using something like /site/<pagename> to make all requests to go there, and then hide the site or something.

Thanks again if anyone could provide some info. And Yii is a great framework. I have discovered how to make components.