2013-09-30 29 views
0
id int(11) 
label1 varchar(10) 
label2 varchar(10) 
label3 varchar(10) 

通过蛋糕烤我创建模型控制器和视图。cakephp节省chekbox值到数据库

现在看来我想用复选框创建表单。

<?php echo $this->Form->create('Check'); ?> 
    <fieldset> 
     <legend><?php echo __('Add Check'); ?></legend> 
    <?php 
    echo $this->Form->input('Check', array(
    'type' => 'select', 
    'multiple' => 'checkbox', 
    'options' => array(
      'label1' => 'label1', 
      'label2' => 'label2', 
      'label3' => 'label3' 
    ) 
    )); 
    ?> 
    </fieldset> 
<?php echo $this->Form->end(__('Submit')); ?> 

但我不能保存数据到我的数据库。是否可以通过复选框将文本写入数据库? 我读了该复选框可以只有1或0的工作。所以我想在我的模型中验证功能之前,但我不知道如何写它。任何人都可以帮助解决这个问题?

Regards

+0

$ this-> Form-> input('Check')你确定在数据库中它的名字是Check? – Aryan

+0

可能的重复问题。检查这[1] [1]:http://stackoverflow.com/questions/14167275/cakephp-submitting-a-multiple-checkbox-input-into-the-database – Sp0T

回答

0

你在控制器的操作中做什么?尝试:

$this->Check->save($this->request->data); 

如果使用此方法且数据未保存,则可能是您的复选框没有值。尝试将value = "1"置于复选框中。