Wednesday, January 28, 2009

Re: What is the advised way to call a function from another controller?

Looks good, but I'd be inclined to further break it up into functions
that return individual lists. There might be a time later on when you
want to just get ethnicities or sexualities or whatever. If need be,
you can wrap them, again within the model class, with one function
that calls all.

On Jan 28, 12:15 pm, WebbedIT <p...@webbedit.co.uk> wrote:
> I have gone with the Model approach as it seems right.  See the
> following and please give your thoughts:
>
> Model:
> ...
> function __formData($authUser = array()) {
>   if ($authUser['User']['user_group_id'] < 3) {
>     $organisations = $this->Organisation->find('list', array(
>       'conditions'=>array('Organisation.is_deleted'=>'0'),
>       'order'=>'Organisation.name ASC'
>     ));
>     $output['organisations'] = compact('organisations');
>   } elseif ($authUser['User']['user_group_id'] == 3) {
>     $organisations = $this->Organisation->find('list', array(
>       'conditions'=>array('Organisation.is_deleted'=>'0',
> 'Organisation.scheme_id' => $authUser['Scheme']['id']),
>       'order'=>'Organisation.name ASC'
>     ));
>     $output['organisations'] = compact('organisations');
>   }
>
>   $users = $this->User->find('list', array
> ('fields'=>'User.username'));
>   $this->set(compact('users'));
>
>   $ethnicities = $this->Ethnicity->find('list', array(
>     'conditions'=>array('Ethnicity.option_list_id'=>'13'),
>     'fields'=>array('Ethnicity.value'),
>     'order'=>'Ethnicity.value ASC'
>   ));
>   $output['ethnicities'] = compact('ethnicities');
>
>   $sexualities = $this->Sexuality->find('list', array(
>     'conditions'=>array('Sexuality.option_list_id'=>'18'),
>     'fields'=>array('Sexuality.value'),
>     'order'=>'Sexuality.value ASC'
>   ));
>   $output['sexualities'] = compact('sexualities');
>
>   $religions = $this->Religion->find('list', array(
>     'conditions'=>array('Religion.option_list_id'=>'30'),
>     'fields'=>array('Religion.value'),
>     'order'=>'Religion.value ASC'
>   ));
>   $output['religions'] = compact('religions');
>
>   $genders = $this->Gender->find('list', array(
>     'conditions'=>array('Gender.option_list_id'=>'12'),
>     'fields'=>array('Gender.value'),
>     'order'=>'Gender.value ASC'
>   ));
>   $output['genders'] = compact('genders');
>   return $output;}
>
> ...
>
> Controller:
> ...
> $formData = $this->Referral->Client->Person->__formData($this->authUser);
>
> foreach ($formData as $key => $value) {
>   $this->set($formData[$key]);}
>
> ...
>
> I believe this fits correctly within Cake's MVC design pattern, but
> I'm fully open to suggestions as to how this can be improved.
>
> Paul.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: