无法从查找查询中检索数据
Cannot retrieve data from find query
在我的事件模型中,我有以下函数来检索状态 = 1 的所有事件,限制为 12,并根据事件创建的顺序排序:
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 并调试它时 returns 六个记录但是当我将我的限制更改为超过 6 时它 returns (空)这个:
我什至通过执行以下查询检查了我的数据库:
SELECT * FROM `events` WHERE `status` = 1 ORDER BY `created` DESC LIMIT 12
和这个 returns 我想要的所需数据。我什至试过了:
$result = $this->query('SELECT * FROM `events` WHERE `status` = 1 ORDER BY `created` DESC LIMIT 12');
但同样的事情也发生在限制上(6 returns 数据,但超过 6 则没有)。
我发现我试图调试的数据有特殊字符,我必须在我的 database.php 中包含 'encoding' => 'utf8'
并且非常有效。这 post 帮助了我。
在我的事件模型中,我有以下函数来检索状态 = 1 的所有事件,限制为 12,并根据事件创建的顺序排序:
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 并调试它时 returns 六个记录但是当我将我的限制更改为超过 6 时它 returns (空)这个:
我什至通过执行以下查询检查了我的数据库:
SELECT * FROM `events` WHERE `status` = 1 ORDER BY `created` DESC LIMIT 12
和这个 returns 我想要的所需数据。我什至试过了:
$result = $this->query('SELECT * FROM `events` WHERE `status` = 1 ORDER BY `created` DESC LIMIT 12');
但同样的事情也发生在限制上(6 returns 数据,但超过 6 则没有)。
我发现我试图调试的数据有特殊字符,我必须在我的 database.php 中包含 'encoding' => 'utf8'
并且非常有效。这 post 帮助了我。