goFrendiAsgard / No-CMS

No-CMS, A CodeIgniter Based CMS Framework
299 stars 199 forks source link

Can I add a custom user field? #64

Closed velsankar closed 11 years ago

velsankar commented 11 years ago

I have the following requirement:

There will be 5 user groups for my application: web_admin, school_admin, teacher, parent, student. Now web_admin should be able to create a school_admin user and associate that user to a specific school.

The application will be used by many schools and the database will contain data of all schools in every table. Now when everytime a school_admin logins, he can view/modify only data related to his school.

Is it a good idea if I include a school dropdown in the Add User page? And when the school_admin logins, set the school_id in cms_ci_session in application/core/MY_Model.php and retrieve from there wherever I need it?

If there is a better way to do it, please brief in a few lines. I should be able to understand.

Also please mention if I am missing out on any pre-existing feature which will meet the above mentioned requirement.

goFrendiAsgard commented 11 years ago

@velsankar: You can add "school" field to the cms_main_user table, but it is probably not the best idea since you'll need a lot of work when you want to update No-CMS to the newer version.

I believe the best idea is make another table (let's say cms_school_user). This table should be a relation table between school and cms_main_user (many to many relation). You can use module generator to help you do this easily. This way, you won't choose the schools when adding a user, but you will choose users when you add (or edit) a school.

PS: We have No-CMS forum (http://www.getnocms.com/forum/) to discuss things like this. Make sure to have a visit there :)

velsankar commented 11 years ago

@goFrendiAsgard: Handling No-CMS update was exactly my concern. Thank you so much for a better idea. But once I have generated a project with my own tables, I can play only with my tables or create a new table right? I am not seeing cms_main_user in my project's tables list to be able to implement your suggestion with module generator. Also I realize I will lose all navigations I have added so far if I generate the module again. Guess I need to create the junction table cms_school_user for e.g with phpmyadmin and hand code the many to many relation. Please correct me if I my guess is wrong.

goFrendiAsgard commented 11 years ago

@velsankar : Yes, you are right. For now, you need to code things manually (at least the code generator has make the job easier isn't it :D ). I hope this will help http://www.grocerycrud.com/documentation

velsankar commented 11 years ago

@goFrendiAsgard: Thank you. Of course, module generator has made life at least a 100 times easier. :-) Absolutely no complaints. I was only trying to understand what is not possible. Thanks a lot again!