Dear All. I would like some advice please. I am new to CakePHP and so far I
am loving it. I am keen to do things the “right way” so I am interested in
any comments.
What I describe in the following I have working. I am interested in knowing
if I have gone about it the right or wrong way.
I have a table with a varchar field that I want to complete with data from
another table – my choices table. There is no connection between the two
tables.
In my controller I have the following:
App::import('Model', 'Choice');
$tmpChoice = new Choice();
$titles = $tmpChoice->find('list', array(
'fields' => array('item', 'item'),
'conditions' => array('cat' => 'title'),
'recursive' => 0
));
$this->set(compact('titles'));
I have this in my view:
echo $this->Form->input('title',
array('type'=>'select','options'=>$titles));
Above, I needed to instantiate the Choice model class to make it available
to my code. When I used:
$titles = $this->MainTable->Choice->find('list',…
I received an error saying that I was trying to execute a function of an
object that isn’t a class. I resorted to my above code to resolve the error.
The “fields” array specifies “('item', 'item')”. This I did so that I could
have the value and the option the same – I didn’t want to insert the id key
into the database, I wanted the text. The “conditions” statement is present
so that I can select the appropriate category of choices.
Thanks for looking at this and making any comments about the code.
With regards
Graham Jones
--
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