For example's sake, lets say that you have User and then UserType, user
types consists of the following records:
Admin, Editor, Contributor, User
You want to have a drop down list with all the user types, so when creating
a new user you can select which type it should be (in this example), you
would do something like this.
*Controller (basic):*
$this->set('userTypes', $this->User->UserType->find('list'));
*View (form):*
echo $this->Form->input('User.user_type_id', array('options' =>
$userTypes));
If you name your field and variable correctly, CakePHP should automatically
pick up that $userTypes holds the options for the 'User.user_type_id' field.
Here is more on it:
http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs
On 6 July 2014 08:07, Tze Pin <[email protected]> wrote:
> May i get some examples on create a drop down list with belongsTo
> relationship? the option that will be show in the drop down list should be
> retrieve from database table. I hardly can't find any examples on this in
> the internet. please help.
>
> thanks in advance.
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>
--
Kind Regards
Stephen Speakman
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.