【问题标题】:Cannot retrieve data from find query无法从查找查询中检索数据
【发布时间】:2017-01-02 09:24:56
【问题描述】:

在我的事件模型中,我有以下函数来检索状态 = 1 的所有事件,限制为 12,并根据创建的事件 DESC 排序:

public function latestEvents() {
    $this->Behaviors->load('Containable');
    $result = $this->find('all' ,array('recursive' => -1, 'conditions'=> array('Event.status' => 1), 'limit' => 12, 'order' => array('Event.created DESC')));
    debug($result); die();
    return $result;
}

此函数不返回任何数据。当我将限制更改为 6 并进行调试时,它会返回六条记录,但是当我将限制更改为超过 6 时,它会返回(空):

我什至通过执行以下查询检查了我的数据库:

SELECT * FROM `events` WHERE `status` = 1 ORDER BY `created` DESC LIMIT 12

这将返回我想要的所需数据。我什至尝试过:

$result = $this->query('SELECT * FROM `events` WHERE `status` = 1 ORDER BY `created` DESC LIMIT 12');

但同样的事情发生在限制上(6 个返回数据,但超过 6 个不返回)。

【问题讨论】:

    标签: cakephp-2.x


    【解决方案1】:

    我发现我试图调试的数据有特殊字符,我必须在我的 database.php 中包含 'encoding' => 'utf8' 并且工作起来就像一个魅力。这个post 帮助了我。

    【讨论】:

      猜你喜欢
      • 2014-06-29
      • 1970-01-01
      • 2021-12-06
      • 2018-10-13
      • 2017-11-23
      • 1970-01-01
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多