我正在使用cakePHP创建HTML复选框,例如:
<?php echo $this->Form->checkbox('medicine_time.0', array('value' => 'morning', 'div' => false, 'label' => false)); ?> Morning
<?php echo $this->Form->checkbox('medicine_time.1', array('value' => 'noon', 'div' => false, 'label' => false)); ?> Afternoon
<?php echo $this->Form->checkbox('medicine_time.2', array('value' => 'eve', 'div' => false, 'label' => false)); ?> Evening
<?php echo $this->Form->checkbox('medicine_time.3', array('value' => 'night', 'div' => false, 'label' => false)); ?> Night
虽然这样,我有一个数组,其值将决定是否选中复选框
数组:
[medicine_time] => Array
(
[0] => morning
[1] => noon
[2] => 0
[3] => night
)
现在,如果我有早晨,则应选中具有相同值的第一个复选框,依此类推。或者如果我将同一数组修改为:
[medicine_time] => Array
(
[0] => morning
[1] => noon
[2] => night
)
会有帮助吗?
我怎样才能实现它?或者任何其他方法?
在控制器中尝试这样的事情:
$this->request->data['model_name'] = array(
'field_name' => 'field_value'
);
呵呵。