Tuesday, January 27, 2009

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

Are you sure a component would be correct for this as again the
CookBook states "To access/use a model in a component is not generally
recommended" and my __formData() functions are made to access models:

function formData() {
$organisations= $this->Person->Organisation->find('list', array(
'order'=>'Organisation.name ASC'
));
$this->set(compact('organisations'));

$users = $this->Person->User->find('list', array
('fields'=>'User.username'));
$this->set(compact('users'));
$ethnicities = $this->Person->Ethnicity->find('list', array(
'conditions'=>array('Ethnicity.option_list_id'=>'13'),
'fields'=>array('Ethnicity.value'),
'order'=>'Ethnicity.value ASC'
));
$this->set(compact('ethnicities'));

$sexualities = $this->Person->Sexuality->find('list', array(
'conditions'=>array('Sexuality.option_list_id'=>'18'),
'fields'=>array('Sexuality.value'),
'order'=>'Sexuality.value ASC'
));
$this->set(compact('sexualities'));

$religions = $this->Person->Religion->find('list', array(
'conditions'=>array('Religion.option_list_id'=>'30'),
'fields'=>array('Religion.value'),
'order'=>'Religion.value ASC'
));
$this->set(compact('religions'));

$genders = $this->Person->Gender->find('list', array(
'conditions'=>array('Gender.option_list_id'=>'12'),
'fields'=>array('Gender.value'),
'order'=>'Gender.value ASC'
));
$this->set(compact('genders'));
}

Also I would still have to create a lot of logic or duplicate
functions within the component so that the find calls were made via
the right associations, i.e. the above function would work fine when
the referencing controller was PeopleController but when called from
ClientController the find calls would have to start $this->Client-
>Person... and from Staff $this->Staff->Person... etc.
--~--~---------~--~----~------------~-------~--~----~
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: