如何解决CakePHP-多行编辑
| 如何对多行表格进行编辑? 我在这里遵循了该教程,网址为http://matsimitsu.com/blog/2008/01/06/saveall-with-cakePHP.html,但它似乎不起作用。 这是我正在做的事情,但是不起作用。 谢谢, 三通function editAll() {
$this->data = $this->Settings->find(\'all\',array(\'conditions\' => $conditions));
}
然后在视图中,这就是我所拥有的
foreach ($this->data as $setting):
echo $form->input(\'Setting.\' . $setting[\'Setting\'][\"id\"] . \'.value\',array(\'value\' => $setting[\'Setting\'][\"value\"]));
endforeach;
然后在添加功能中我有
function add() {
if (!empty($this->data)) {
$this->Setting->create();
if ($this->Setting->saveAll($this->data)) {
$this->Session->setFlash(__(\'The Setting has been saved\',true));
$this->redirect(array(\'action\' => \'index\'));
} else {
$this->Session->setFlash(__(\'The Setting Could not be saved. Please,try again.\',true));
}
}
}
解决方法
您需要包括“ 3”字段,因此控制器中的数据将如下所示:
\'Setting\' => array(
0 => array(
\'id\' => 42,\'value\' => \'foo\'
),1 => array(…)
)
因此,在视图中,执行以下操作:
foreach ($this->data as $i => $setting) {
echo $this->Form->hidden(\"Setting.$i.id\",array(\'value\' => $setting[\'Setting\'][\'id\']));
echo $this->Form->input(\"Setting.$i.value\",array(\'value\' => $setting[\'Setting\'][\'value\']));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。