change:
$types = $this->UrlsUser->Type->find('list',....
to
$types = $this->UrlsUser->Type->find('all',.....
Then:
$types = Set::combine($types, '{n}.UrlsUser.Type.id',
'{n}.UrlsUser.Type.type');
I think. Those paths in the combine reflect how the data is, in the array
return from find->('all')... you may want to do a quick debug($types) before
this make sure the data is in the correct form.
But essentially, the [{n}] refers to the number of the particular result,
and the rest of the string is supposed to match the array structure.... So
what I have about will work for [0][UrlsUser][Type][id]....If your data is
different just make the strings match.
Why do you need this? ->find('list') automatically setups up IDs with
another field called 'title/name' (maybe some others). If not, it uses ID.
Good luck.
--
Baz L
Web Development 2.0
http://WebDevelopment2.com/
On Feb 12, 2008 12:36 PM, cartosys <[EMAIL PROTECTED]> wrote:
>
> Ok, spent many hours looking for appropriate syntax for the formhelper
> and controller in 1.2 for this (looked in manuals, API, groups, blogs
> etc.). I've decided that I will donate $10 if this issue is resolved!
>
> here's the tables:
>
> urls_users
> +-----------------+------------------+------+-----+---------
> +----------------+
> | Field | Type | Null | Key | Default |
> Extra |
> +-----------------+------------------+------+-----+---------
> +----------------+
> | id | int(10) unsigned | NO | PRI | NULL |
> auto_increment |
> | type_id | int(10) unsigned | NO | MUL | 1
> | |
> | description | blob | YES | | NULL
> | |
> | created | datetime | YES | | NULL
> | |
> | modified | datetime | YES | | NULL
> | |
> +-----------------+------------------+------+-----+---------
> +----------------+
>
> belongsTo:
>
> types
> +-------+------------------+------+-----+---------+----------------+
> | Field | Type | Null | Key | Default | Extra |
> +-------+------------------+------+-----+---------+----------------+
> | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
> | type | varchar(20) | YES | | NULL | |
> +-------+------------------+------+-----+---------+----------------+
>
>
> I've baked an 'add' view using urls_users with a form in which I want
> a select box populated with Type.type. The default bake does
> everything I want except lists the Type.id instead of Type.type. Here
> are the controller elements and formhelper stuff:
>
> //controller
> $types = $this->UrlsUser->Type-
> >find('list',array('fields'=>array('Type.id','Type.type')));
>
>
> //view
> echo $form->input('type_id');
>
>
> So i modified the controller arguments to include Type.type since the
> default find('list') only returned numerical id's. The resulting
> query, as displayed at the bottom of the default page view (by the
> paginater?),
>
> "SELECT `Type`.`id`, `Type`.`type` FROM `types` AS `Type` WHERE 1 =
> 1"
>
> does yield the desired results in mysql:
>
> +----+-----------+
> | id | type |
> +----+-----------+
> | 1 | Masculine |
> | 2 | Feminine |
> +----+-----------+
>
>
> So I figure I'm missing some syntax either in the view or controller
> at or near the above mentioned lines (as far as I can tell). Any help
> on how this associated data can be displayed in the selectbox?
>
> Thx,
> -B
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---