cakephp:将数据保存到另一个模型

时间:2013-06-03 04:17:06

标签: forms cakephp

好的我有2张桌子= shop& tag

目前在我的商店查看文件中 我有一张表格。

像是一样的东西 echo $this->Form->input('tag_id');
echo $this->Form->input('tag1');
echo $this->Form->input('tag2');

好吧,现在在我的商店控制器...... if($this->request->is['Post'] {
$this->Tag->id = $this->data['Shop']['tag_id'];
$this->Tag->save($this->request->data);

你有办法吗?实际上我想得到商店视图文件输入的表单值,但保存到标签表... 但商店控制器代码不起作用...我想这是$this->Tag->id = $this->data['Shop']['tag_id'];部分是错误的。有帮助吗?

2 个答案:

答案 0 :(得分:0)

您需要正确引用模型:$this->Shop->Tag->id=...; $this->Shop->Tag->save(...)我很惊讶您在引用Tag模型时没有收到错误消息。

答案 1 :(得分:0)

你实际上可以尝试用它来管理。

if($this->request->is['Post'] {
     $this->Tag->id = $this->data['Shop']['tag_id'];
     $save_arr['Tag']['tag1'] = $this->data['Shop']['tag1'];
     $save_arr['Tag']['tag2'] = $this->data['Shop']['tag2'];
     $this->Tag->save($save_arr);
} 

请告诉我是否可以为您提供更多帮助。

相关问题