I posted this on Stack Overflow as well.
I have had a good play around with the Yii Framework and now I want to take it a bit deeper and what I want to do is set up an application where several different URLs would point to the same controller.
Normally domain.com/content will point to class ContentController which is standard in MVC.
What I want to do is set up three controllers (maybe more but this will do to start), i.e. ArticlesController, DisplayController and SplashController.
I would then set up what is essentially a CMS for a client, and they would be able to create as many pages as they want and point them to the above three controllers, which I have already set up to handle the data.
So for instance my client could set up the following pages: news, notices, technical and have them all pointed to the ArticlesController, and also set up pages: management, specials, support and have them all pointed to the DisplayController.
I know that all those controllers could be creating using the Gii module, but in this case its not an option as I don’t think that’s suitable for non technical people.
I just want my client to be able to log into the CMS, decide he wants to create a new page called "randompage", point it to the ArticlesController using a drop down menu, then write a bunch of articles for it and now have those articles accessible at domain.com/randompage/article-1 domain.com/randompage/article-2
With the standard set up that would point to site/error because there is no controller RandompageController
What I’ve done so far is create a constructor in Controller class where I can overwrite the controller id
class Controller extends CController {
function __construct($id) {
// Code here which successfully pulls from the database
// which controller the current page should point to.
parent::__construct($newControllerID)
}
}
If I check in the CController class, $this->_id = either articles, display or splash but the application itself stills loads site/error
I’m guessing I must have to set/override the Controller elsewhere. I have tried
Yii::app()->setController($newControllerID)
but that doesn’t have any effect
Perhaps Yii is set up and must require a specific controller for each URL but that would mean developing rather rigid solutions for clients, and requiring them to call in the developer every time they want to add a new controller.
One other solution I’ve thought if is that I could load all pages and their controller’s from the database when I start up the application and load them into the url of the config/main.php file?
Hope I have explained what I’m trying to do well.