2012-08-07 80 views
1

大家从我的下拉框中数据没有正确保存到数据库中,它的储蓄外键template_id作为nullCakePHP的下拉框数据不保存到数据库

这里是功能

function add(){ 


$this->Session->setFlash("Please create your required fields."); 
$templates = $this->Template->find('all', array('fields' => array('Template.id'))); 
$this->set('templates', $templates); 

    if($this->request->is('post')) 
    { 

    $this->Field->create(); 

    if ($this->Field->save($this->request->data)) 
    { 
     if($this->request->data['submit'] == "type_1") 
      { 
       $this->Session->setFlash('The field has been saved'); 
       $this->redirect(array('controller' => 'fields','action' => 'add')); 
      } 
      if($this->request->data['submit'] == "type_2") 
      { 
       $this->Session->setFlash('The template has been saved'); 
       $this->redirect(array('controller' => 'templates','action' => 'index')); 
      } 


    } 
    else 
    { 
     $this->Session->setFlash('The field could not be saved. Please, try again.'); 
    } 
} 
    } 

这里是视图

<?php 

echo $this->Form->create('Field', array('action'=>'add')); 

echo $this->Form->create('Field', array('action'=>'add')); 
echo $this->Form->input('name', array('label'=>'Name: ')); 
echo $this->Form->input('description', array('label'=>'Description: ')); 
echo $this->Form->input('template_id',array('label'=>'Template ID: ', 'options' => $templates)); 
echo $this->Form->button('Continue adding fields', array('name' => 'submit', 'value' => 'type_1')); 
echo $this->Form->button('Finish adding fields', array('name' => 'submit', 'value' => 'type_2')); 
echo $this->Form->end(); 

?> 
+0

请解释'pr($ this-> request-> data)'显示什么? – 2012-08-07 11:40:20

+0

阵列 ( [提交] => TYPE_2 [字段] =>数组 ( [名称] => TEST1 [描述] =>喜 [template_id] => 100000 ) ) – user1393064 2012-08-07 11:43:23

+0

如果上述你收到的数组然后它应该被保存。 – 2012-08-07 11:49:46

回答

0

对不起你们,这是一个漫长的一天,它被保存校正的信息。

+0

但如何?你没有向后来的观众解释并寻找答案。谢谢 – Meer 2014-10-19 21:16:24