2017-02-21 6 views
0

Ich habe Probleme beim Erstellen von CakePHP-Option Wert.Optionswert in der Dropdown-Liste

Mein Code in add.ctp

<h1>New Book</h1> 
<?php 
echo $this->Form->create('Book',array('enctype'=>'multipart/form-data')); 
echo $this->Form->input('title'); 
echo $this->Form->input('author'); 
echo $this->Form->input('summary',array('rows' => '3')); 
echo $this->Form->input('category',array('type'=>'select','options'=>$category)); 
echo $this->Form->input('price'); 
echo $this->Form->input('image',array('type'=>'file')); 
echo $this->Form->end('Save'); 
?> 

und Controller-Add-Funktion

public function add(){ 
    $this->loadModel('Category'); 
    $category =$this->Category->find('all', array('fields'=>'name')); 
    debug($category); 
    $this->set('category',$category); 
    if($this->request->is('post')){ 

    $this->Book->create(); 
    $filePath="./img/images/".$this->request->data['Book']['image']['name']; 
    $filename=$this->request->data['Book']['image']['tmp_name']; 
    if(move_uploaded_file($filename, $filePath)){ 
     $this->request->data['Book']['cover']=$this->request->data['Book']['image']['name']; 
    } 
    if ($this->Book->save($this->request->data)) { 
     $this->Flash->success(__('Your book has been saved.')); 
    } 
    return $this->redirect(array('controller' =>'Books','action' => 'index')); 
    } 
} 

Ich möchte nur in meinen Kategorien Namen meines Listenfeld kann nicht mit foreach in meiner Form tun. Warum?

+0

http://stackoverflow.com/questions/42291925/how-to-display-an-array-of-fetched-data -von-Datenbank-zu-Dropdown-Liste-in-Kuchen/42292168 # 42292168 – drmonkeyninja

Antwort

0

ändern

$category =$this->Category->find('all', array('fields'=>'name'));

Um

$category =$this->Category->find('list');