Yii Framework Forum: General Object Design Question - Yii Framework Forum

Jump to content

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

General Object Design Question Rate Topic: -----

#1 User is offline   FlyBy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 28-February 13

Posted 15 March 2013 - 05:15 PM

Hello,

Curious about how best to design a few classes. This is a simplified version, but just looking for concepts. Say I have 3 tables: Users, Departments, User_Departments.

A Manager is able to add an Employee (both Sub classes of User) to the User_department table. Where should this action reside?


Should this be in the Manager Controller (An extended UserController class), as it’s the job of the manager to add Users to this table? Or in the Department Controller, as the department controller should be responsible for actions relating to departments. Finally, should I create a User_Department Controller and store it in there.

While all 3 cases would work, I am looking for what’s the best practice, and for possible future changes, what would be easier.

Thanks in Advanced.
0

#2 User is offline   acorncom 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 99
  • Joined: 25-February 11
  • Location:CO, USA

Posted 19 March 2013 - 12:36 AM

Either of your options would work (adding from a user point of view or from a department point of view). Which makes more sense from your users' perspective? Do that :-)
0

#3 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,688
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 19 March 2013 - 01:01 AM

Also you can implement it in either controller, using class-based actions.

For example, create a CBA that takes two params: userId and departmentId.
Then create references to this class in both controllers using actions() array.

So basically you can have two URLs, (user/add_to_department and department/add_user) doing the same thing, without repeating the code.

I don't know if it's good or bad in your case, but anyway it's another option.
God is real unless declared as integer
0

#4 User is offline   Boaz 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 359
  • Joined: 23-January 11

Posted 20 March 2013 - 02:44 AM

I would have probably NOT created a separate class for managers and employees. Both would have been users. As for permissions control, I would have made manager, employee 'roles' in the RBAC system, where there would have been simple permissions as well like 'change dept', 'assign as manager' etc. These roles and permissions needs to be organized into a (rather simple and intuitive) RBAC tree and assigned to 'users' in your system.
As for in which controller to place the action to handle assignment of users to departments? That's a matter of UI and is less important, probably. You can have it done from the department controller or from users controller. YYMV, according to you tendencies and requirements.
Therapeutic PHP sessions My LinkedIn Profile
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