Write following in your DealersController class:

$subdivisions = $this->Country->find("all",array('fields' =>
array('Country.id','Country.name') ));
$result = Set::combine($subdivisions,
'{n}.Country.id','{n}.Country.name');
$this->set('countrylist',$result);

Before this don't forget to add Country Model to your
DealersController as following:

var $uses = array('Dealer','Country');

and then write the following to your view file:

<?php echo $form->input('country_id', array('options' =>
$countrylist , 'label' => 'Select Country')); ?>

francky. generatelist also works but is deprecated in version 1.2


On Jan 16, 4:39 pm, Barry <[EMAIL PROTECTED]> wrote:
> Hallo
>
> I'm new to cakePHP and quite excited. I've been looking for something
> like this for quite some time.
> Started off with 1.1 and moved over to 1.2 immediately. Its been a bit
> of a struggle.
>
> I've got 2 models:
>
> class Dealer extends AppModel
> {
>
>         var $name='Dealer';
>
>         var $validate=array();
>
>         var $belongsTo = array(
>                         'Country'=>array('className'=>'Country')
>                 );
>
> }
>
> class Country extends AppModel
> {
>
>         var $name='Country';
>
>         var $hasMany = array(
>                         'Dealer'=>array('className'=>'Dealer')
>                 );
>
> }
>
> My countries table has 2 fields, id and name and my dealers table
> references it with country_id.
>
> When a dealer registers (using add action), I need to generate a
> <select> list so that the dealer may select which country is home. I'm
> trying to get this right without using a custom query.
> Surely this must be a common problem, but I can't find anything
> documenting how to do this.
>
> Please help!
>
> Thanks
> Bary
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to