cakephp save 返回 true 但不保存
CakePHP 快把我逼疯了!
这是我的代码:
if($this->Page->save($datavalue))
{
$this->Session->setFlash('Page content updated successfully.');
}
else
{
$this->Session->setFlash('Page content was not updated.');
}
它总是说更新成功,但数据库中没有任何更新。 以下是 $datavalue 的内容:
Array
(
[Page] => Array
(
[id] => 1
[name] => home
[title] => Home page1
[meta_keywords] => keyword1
[meta_description] => this is home page
[content] => home page content
[sidebar] => sidebar content
)
)
我是 CakePHP 的新手,您能给我一个大概的了解,它可能有什么问题吗?
提前致谢。
-happyhardik
这是我的模型代码:
<?php
class Page extends AppModel
{
var $name='Page';
var $useTable = false;
}
?>
希望这有帮助! 我尝试在保存之前添加这两行,希望它会有所帮助:
$this->Page->set($datavalue);
$this->Page->id = $id;
但它们都没有帮助。
这是表结构:
id int(10) UNSIGNED auto_increment Primary
name varchar(250)
title varchar(250)
meta_keywords text
meta_description text
content text
sidebar text
created datetime
modified datetime
如果需要更多信息,请告诉我。 感谢您的阅读。
CakePHP is driving me nuts!
Here is my code:
if($this->Page->save($datavalue))
{
$this->Session->setFlash('Page content updated successfully.');
}
else
{
$this->Session->setFlash('Page content was not updated.');
}
it always says updated successfully, but nothing is updated in the database.
Here is the content of $datavalue:
Array
(
[Page] => Array
(
[id] => 1
[name] => home
[title] => Home page1
[meta_keywords] => keyword1
[meta_description] => this is home page
[content] => home page content
[sidebar] => sidebar content
)
)
I am new to CakePHP, can you please give me a general idea of what could be wrong with it?
Thanks in advance.
-happyhardik
Here is my model code:
<?php
class Page extends AppModel
{
var $name='Page';
var $useTable = false;
}
?>
Hope this helps!
I tried to add this two lines before save, in a hope that it will help:
$this->Page->set($datavalue);
$this->Page->id = $id;
but none of them helped.
Here is the table structure:
id int(10) UNSIGNED auto_increment Primary
name varchar(250)
title varchar(250)
meta_keywords text
meta_description text
content text
sidebar text
created datetime
modified datetime
Let me know, if need any more information.
Thanks for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,您没有使用任何表,这使得
save()
几乎是一个 NOOP。 :-)删除该行,你应该没问题。
Well, you're not using any table, which makes
save()
pretty much a NOOP. :-)Remove that line and you should be fine.
我遇到了同样的问题,谷歌把我带到这里,
我启用了
public $scaffold
,因此保存无法工作。仅供参考,以防有人遇到同样的问题
Im having the same problem and google bring me here
I enabled
public $scaffold
and thus the save wont work.just a reference incase anyone have the same problem