Using more than one Module simultanously

Hi everyone,

i really like the concept of modules in yii. You create your generic part of an Application once, and re-use it as a

pluggable Module everywhere you want.

Unfortunately i have encountered a problem. I think this is a design flaw in the module System of yii:

It’s my Goal to have two different modules, the well-knows SRBAC for the Administration of user privilegies, and

a Module called ‘user’ that handles User Authentication, Messaging between users, User Profile Management, Password

recovery and so on.

I have one Table called ‘users’ containing all users. This table is shared by both modules. That means:

The model::User() of module srbac as well as the model::User() of module user have the same tableName() .

This is no problem so far, but now it gets interesting:

To make both modules as reusable as possible, both modules define their ‘userClass’-Name in the Module Configuration.

This looks like this:

'modules' => array(

		'user' => array(

			'userClass' => 'Users'), 

		'srbac' => array(

			'userClass' => 'Users'),

When running actions under srbac/ everything works fine, as well when running actions under user/ standalone.

But now i want to make it possible, for example, to call a method of the User::model() that’s located in the other module.

Unfortunately this won’t work because the Yii::app()->controller->module is always set to the module thats actual running.

Yii will include modules/module1/models/model.php instead of the modules/module2/models/model.php that contains my wanted Method.

What needs to be made possible is a switch/toggle made available at runtime so one can decide which Module should be accessed

under the actual context in the action executed.

btw: the same problem occurs when i try to access a module Model from outside of the Model.

Maybe i have understood something wrong and there is an easy solution to this situation? What do you think?

Why do you want to put the User model into the module? Just put it into the top level models directory.

I had a look at your Yii-user code. All the problems when running together with sRBAC are caused by having the User model in the Yii-user models folder. There should really be no attempt to run two models on the same DB table.

Ok, so if i understand right, the solution would be to create a User-Model that’s compatible with yii-user as with srbac and always put it in the approot/protected/models folder.

It was my thought that the User-Module would be somewhat more reusable when the User-Model resides in the Module folder. But it is not much effort to just move it over to the approot when installing the Module.

Exactly right. The User entity is most probably used in the application anyhow, not only for user management and authorization. Think of mailing lists, customer reports and so on.

In fact it is bad practice to have multiple model classes for one single DB table.

Also as a hint: put the various URL definitions (now in the Yii-User User model) into the UserController where they really belong to. Then you can use CHtml::normalizeUrl to generate the correct URLs for the module in the controller and/or the views.

Ok, thank you for your hint!

Since i am interested in learning to write high-quality modules (or code in General) i will use normalizeUrl now. I always had my problem with hard-coding the module name in the link, for example array(/user/user/create) … Now your way is the solution.

my next versions will have these changes.

Hi thyseus, when do you think this change will have ready? seems very interesting, especially to use your module and Srbac module.

Thanks a lot