我有一个名单,我需要在"复选框"我需要通过CakePHP将那些经过检查的名称插入到SQL中。有人建议使用:
$this->Form->input('Members', array('multiple' => 'checkbox'));
我不确定它的作用。
答案 0 :(得分:2)
这里我只是向您演示如何保存多个复选框的值。 例如//add.ctp
<em>How would you describe your job (mark as many as applies): </em>
<?php
$options = array(
'Physical' => 'Physical',
'Mental' => 'Mental',
'Stressful' => 'Stressful',
'Easy-going' => 'Easy-going',
'Secure' => 'Secure',
'Non-secure' => 'Non-secure',
'Exhausting' => 'Exhausting',
'Relaxing' => 'Relaxing'
);
echo $this->Form->input('describeJob', array('label' => false,
'div' => false,
'type' => 'select',
'multiple'=>'checkbox',
'legend' => 'false',
'options' => $options
));
?>
//在控制器中
public function somthing() {
if (!empty($this->data)) {
$this->data['Model']['describeJob'] = implode(",",$this->data['Model']['describeJob']);
$this->Model->create();
$this->Model->set($this->data);
$this->Model->save();
}
}
我希望这会对你有所帮助。