Yii Framework Forum: Using more than one Module simultanously - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Using more than one Module simultanously Calling a Module's properties from another makes problems Rate Topic: -----

#1 User is offline   thyseus 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 300
  • Joined: 18-April 09
  • Location:Leipzig, Germany

Posted 17 February 2010 - 12:41 PM

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?
0

#2 User is offline   gmm 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 09-November 09

Posted 21 February 2010 - 07:10 PM

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.
0

#3 User is offline   thyseus 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 300
  • Joined: 18-April 09
  • Location:Leipzig, Germany

Posted 22 February 2010 - 06:39 AM

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.
0

#4 User is offline   gmm 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 09-November 09

Posted 22 February 2010 - 09:33 PM

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.
0

#5 User is offline   thyseus 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 300
  • Joined: 18-April 09
  • Location:Leipzig, Germany

Posted 23 February 2010 - 08:37 AM

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.
0

#6 User is offline   TeKi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 15
  • Joined: 07-March 10

Posted 25 March 2010 - 05:16 AM

View Postthyseus, on 23 February 2010 - 08:37 AM, said:

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
Yii development
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users