CakePHP的下拉框数据不保存到数据库
问题描述:
大家从我的下拉框中数据没有正确保存到数据库中,它的储蓄外键template_id
作为null
CakePHP的下拉框数据不保存到数据库
这里是功能
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();
?>
请解释'pr($ this-> request-> data)'显示什么? – 2012-08-07 11:40:20
阵列 ( [提交] => TYPE_2 [字段] =>数组 ( [名称] => TEST1 [描述] =>喜 [template_id] => 100000 ) ) – user1393064 2012-08-07 11:43:23
如果上述你收到的数组然后它应该被保存。 – 2012-08-07 11:49:46