cakephp下拉框数据未保存到数据库

时间:2012-08-07 10:54:22

标签: database cakephp

嗨我的下拉框中的所有数据都没有正确保存到数据库,它保存为外键template_id null

这是函数

  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();

 ?>

1 个答案:

答案 0 :(得分:0)

抱歉,这是一个漫长的一天,它正在保存纠正信息。