multiple instantiations of a module

Hello everyone,

I’m fairly new to Yii. I’ve done a small personal project in it, it wasn’t very complex. I’m now starting on a new project for work that I would like to do in Yii. However, I have some architecture questions before I begin.

What I need to create is essentially an online application. It has several pages filled with form fields that a user fills out and submits. I need the ability to quickly brand this application for various partners we have. I can store the css colors and background images and what not in a database pretty easily.

The catch is, different partners might have different form applications. I was considering making generic form applications for different levels of partners and placing them in modules. But I’m confused about how Yii should handle the url routing. I know how Yii handles routing with modules:


h**p://example.com/module1/site/index

would take you to the module1 module, the site controller, and the index action. But I want to give each partner a unique url. Something like:


h**p://example.com/partner1/site/index

Then my code would be able to recognize that specific partner name, do a database query and pull out the correct module and branding.

I don’t know how to do this elegantly. I guess I would have to modify the root index.php and do a query each time a page is requested then somehow rewrite the url on the backend to direct it to the correct module. But I need some help with this. Do you guys have any tips?

Welcome to the forum.

You should read this section in the guide about Custom Url Rule Classes.

/Tommy

Thanks, I ended up going on the yii irc channel and found some awesome help there. A user named blindMoe suggested that I use the url rules to direct requests to a specific controller/action. Then I can take in the url parameters as arguments, do a database lookup, and figure out the correct module and branding from there. So my url rules look like:




                'urlManager'=>array(

                        'urlFormat'=>'path',

                        'rules'=>array(

                                // route ALL urls to routing/index

                                ''=>'routing/index',

                                '<module:\w+>'=>'routing/index',

                                '<module:\w+>/<action:\w+>'=>'routing/index',

                                '<module:\w+>/<action:\w+>(.*)'=>'routing/index',

                                //'<controller:\w+>/<id:\d+>'=>'<controller>/view',

                                //'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

                                //'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

                        ),  

                ),  



and then my routing/index action looks like this:




class RoutingController extends Controller

{

        // ALL urls go to this controller/action. Arguments are passed in via GET.

        // If the user does not specify a module or action, use the default ones.

        public function actionIndex($module = "defaultModule", $action = "defaultAction")

        {   

                // database lookup on $defaultModule, return module name in $moduleName

                // $action would be the same

                 $this->forward("$moduleName/$action");

        }   

}