I got a little "problem" with CakePHP. My code is working fine, but I am looking for a way to shorten the code.
I have a model called "Document" and it "belongsTo" several "User"s.
- creator
- editor
- responsiblePerson
In my Controller I use the following code to load a list of all the available users:
$creators= $this->Document->Creator->find('list');
$editors= $this->Document->Editor->find('list');
$responsiblepersons= $this->Document->Responsibleperson->find('list');
$this->set(compact('creators','editors','responsiblepersons');
Now I can use this code in my views:
echo $this->Form->input($creator_id);
echo $this->Form->input($editor_id);
echo $this->Form->input($responsibleperson_id);
This is working fine, but is it really necessary to find all 3 lists? In my controller $creators, $editors & $responsiblepersons contain all the same elements. Overall one "Document" is connected to 6 different "User"s, so this is really bloating my code.
Any idea? Thanks!