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.
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 www.example.com/home.
User goes to the frontend and types in www.example.com/home 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.
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:
'<category>/<slug:[a-z0-9-]+>'=>'page/view',
There is an extension called ‘SlugBehavior’ which can help you create slugs for your pages from titles, like in Wordpress.
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 .
But to come back. I have currently managed to write the first levels meaning example.com/home to a pageController that handles the request as follows. But it doesn’t work for example.com/home/about_us. Below is what I changed in the config of main.php
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array(
'/'=>'/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.