cakephp save 返回 true 但不保存

发布于 2024-08-09 13:51:29 字数 1388 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嗫嚅 2024-08-16 13:51:29
var $useTable = false;    

好吧,您没有使用任何表,这使得 save() 几乎是一个 NOOP。 :-)

删除该行,你应该没问题。

var $useTable = false;    

Well, you're not using any table, which makes save() pretty much a NOOP. :-)

Remove that line and you should be fine.

说谎友 2024-08-16 13:51:29

我遇到了同样的问题,谷歌把我带到这里,

我启用了 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文