Wednesday, May 23, 2012

Re: Need help populating a select box

On Tue, May 22, 2012 at 3:25 PM, dpinion <dpinion@gmail.com> wrote:
> Ok, I am somewhat new to cake, have spent the past two days on this
> and I am just not getting it. Hope someone can shed some light on it
> for me. I have two tables:

>
> icons_controller.php:
>
> <?php
> class IconsController extends AppController{
>  var $name = "Icons";
>  var $uses = array('Icon', 'Product');
>
>
>  function assignFields(){
>    $productId = $this->params['named']['product_id'];
>    $icons = $this->Icon->findAll(array('product_id' => $this->params['named']['product_id']));
>    $this->set('icons', $icons);
>  }
> }
>
> ?>
>
>
> index.ctp:
>
> <?php echo $form->input('icon_num', array('type' => 'select',
> 'options' => $icons, 'label' => 'Choose Icon ID:'))?>
>
>
>
> The select is being populated with fields from both the icons tables
> as well as the products table. I really ONLY want to display the
> filename field from the IconCategory model along with storing the id
> into the product_icons' icon_id field.
>
> Hope this makes sense. Thanks for any help.

That's because you are passing the result of a findAll request to the input tag.
Have a look at find('list')
http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#find-list

You'll have to add some conditions to get the exact data that you want
back but this is the format you want it in.

Mike.

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: