Thursday, October 29, 2009

Re: Multi-value field in cake


when  get a problem with multi-value ,I think this code can help you ,this is me code ,

Controllers:

    function add() {
        if (!empty($this->data)) {
            $this->Wine->create();
            //saveAll(), NOT save()
            if ($this->Wine->saveAll($this->data)) {
                $this->Session->setFlash(__('The Wine has been saved', true));
                $this->redirect(array('action'=>'index'));
            } else {
                $this->Session->setFlash(__('The Wine could not be saved. Please, try again.', true));
            }
        }
        $grapes = $this->Wine->Grape->find('list');  //multi-value
        $types = $this->Wine->Type->find('list');
        $wineries = $this->Wine->Winery->find('list');
        $this->set(compact('grapes', 'types', 'wineries'));
    }

view
        <?php
            echo $form->input('name', array('label' => __('Name', true)));
            echo $form->input('description', array('label' => __('Description', true)));
            echo $form->input('year', array('label' => __('Year', true)));
            echo $form->input('selling_price', array('label' => __('Selling Price', true)));
            echo $form->input('discount', array('label' => __('Discount', true)));
            echo $form->input('type_id', array('label' => __('Type', true)));
            echo $form->input('winery_id', array('label' => __('Winery', true)));
            echo $form->input('Grape', array('label' => __('Grape', true), 'multiple' => 'checkbox')); //multi-value, checkbox
           
            echo $form->input(null, array('label' => __('WinePhoto', true), 'type' => 'file', 'name' => 'data[WinePhoto][]', 'id' => 'files'));
            echo $html->link('+', '#', array('id' => 'file-more'));       
        ?>

all ok

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: