CakePHP中保存多个数据
问题描述:
我写它看起来像这样的自定义视图: http://img405.imageshack.us/i/taula.jpg/CakePHP中保存多个数据
这是我没有控制器功能保存尚未实现的数据: http://pastebin.com/cU5rprFB
这是我的观点: http://pastebin.com/4bYLPp4z
我以为写这样的输入是这样的:
<td>
<input name="data[Linea][0][proyecto_id]" type="hidden" value=" <?php echo $proyecto['Proyecto']['id'] ?>" />
<input name="data[Linea][0][hito_id]" type="hidden" value=" <?php echo $proyecto['Hito']['id'] ?>" />
<input name="data[Linea][0][tarea_id]" type="hidden" value=" <?php echo $proyecto['Tarea']['id'] ?>" />
<input name="data[Linea][0][total_horas]" type="text" id="LineaTotalHotas" value="" >
</td>
就足够了......但事实并非如此。在debug_kit中,我发现隐藏的数据正常,但输入的数据丢失了...
有没有人有一个例子或什么来帮助我?
UPDATE:我想类似的东西在我的控制器:
function addhoras() {
if (!empty($this->data)) {
xdebug_break();
foreach($this->data['Linea'] as $l) {
if (($l['total_horas'] != 0) && ($l['total_horas']!=NULL)) {
$this->Linea->create();
if ($this->Linea->save($l)) {
} else {
$this->Session->setFlash(__('Arazonbat eon dek', true));
}
}
}
//$this->redirect(array('action' => 'addhoras'));
}
但我发现了在if ($this->Linea->save($l))
线setflash ...所以它不保存任何数据..这是var_dump($l)
:
array
'proyecto_id' => string ' 1' (length=2)
'hito_id' => string ' 3' (length=2)
'usuario_id' => string ' 1' (length=2)
'fecha' => string '2011-01-01 ' (length=11)
'total_horas' => string '33' (length=2)
答
确保您构建正确的阵列http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM
如果您要保存相关数据,请记住使用saveAll而不是保存。
+++++++++++++++++
TENGO拉corazonada德阙hablas EN卡斯特拉诺,ASI阙褐VA连接卡斯蒂利亚ŸMEJOR explicado:
Asegúrate德que el array que le pasas almétodo“save”tiene la estructuratípicade Cake。埃斯托SERIA算法中的a-Si:
array
(
[Modelo] => array
(
[celda] => valor
)
)
Ÿrecuerda阙SI quieres和保存DATOS relacionados(雅肖恩的hasManyØHasAndBelongsToMany ..)debes utilizar “白水” 恩卢格德 “保存”
安永! gracias por tu respuesta – 2010-12-23 07:29:57