I'm achieving a similar objective by adding an id field to each
model's table to relate to (in your example) schools. Then, in the
classes_controller.php actions, I'd include the line
$school_id = $this->Session->Read('Auth.User.school_id');
and then when building the query include (for example):
$person = $this->Class->find('first', array(
'conditions' => array(
'Class.school_id' => $school_id,
'Class.id' => $id
),
'fields' => array([foo, bar])
));
$this->set('person', $person);
...and this looks pretty much the same as what you're doing. It's
working for me.
(but you'll need to make your models save 'school_id' from session
whenever a user updates/adds a record... I'm using a behavior for that
purpose, a modified version of Daniel Vecchiato's WhoDidIt at
https://github.com/danfreak/4cakephp/tree)
On May 4, 12:27 am, rockbust <[email protected]> wrote:
> Hi all,
>
> I am developing a app and I am new to cake and somewhat new to php. Here
> is what I have . Multiple admins each with admin control over their schools
> (groups). When the admin goes to admin/templates/index they only should see
> templates that belongTo that school. below is how I do this. All seems well.
> The problem is when models do not directly belong to school. Ex: "Room"
> belongs to "School", "Program" belongs to "Room", "class" belongs to
> "program", "schedule" belongs to "class". so if admin (school #1) goes to
> admin/schedules/index how do I alter the query to display only classes with
> extended model association to school #1 .
>
> here is what I am doing: in appcontroller, beforeFilter I read the session
> data:
>
> $user_group_id = $this->Session->read('Userinfo.group_id');
> $session_school_id =
> $this->Session->read('Userinfo.currentSchoolid');
> if ($user_group_id == 1) {
>
> // make currentAdminSchoolId available to all models
> $this->{$this->modelClass}->currentAdminSchoolId =
> $session_school_id;
> }
>
> then in the template model I alter $queryData to reflect school_id:
>
> function beforeFind($queryData) {
> //debug ($this->Session->read('Userinfo.school_id'));
> $queryData['conditions'] = array('school_id =
> '.$this->currentAdminSchoolId);
> return $queryData;
> }
>
> Thanks
> Robert
>
> --
> View this message in
> context:http://cakephp.1045679.n5.nabble.com/how-would-YOU-do-this-admin-grou...
> Sent from the CakePHP mailing list archive at Nabble.com.
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php