Phalcon PhP - model::find 是否有 EOF
Phalcon PhP - is there an EOF for model::find
我正在写一段代码,我想知道其中的查找结果是否为空。这是我的一段代码:
public function signatureAction()
{
$info = $this->session->get('current_quote');
$object_list = ApplicationSignatureFile::find(array('conditions' => 'application_id = ?1 AND quote_id = ?2',
'bind' => [
1 => $info['application_id'],
2 => $info['quote_id'],
]));
$this->view->setVar('object_list', $object_list);
if ($object_list) {
$this->view->setVar('has_files',true);
} else {
$this->view->setVar('has_files',false);
}
}
我还不知道如何检查 $object_list
是否为 EOF,以便我可以更好地设置 has_files
变量。目前它不工作。我如何在控制器和 .volt
视图中做到这一点?
这其实很奇怪。使用 findFirst
或任何其他 ORM 方法 returns false
会失败,但是使用 find
不会。
针对您的情况,一个简单的解决方法是对结果集使用 count
方法:
$test = \Models\Objects::find([
'conditions' => 'is_active = 42'
]);
if ($test->count()) {
print('I have records with is_active = 42');
d($test->toArray());
} else {
print('I do not have any records with is_active = 42');
}
我正在写一段代码,我想知道其中的查找结果是否为空。这是我的一段代码:
public function signatureAction()
{
$info = $this->session->get('current_quote');
$object_list = ApplicationSignatureFile::find(array('conditions' => 'application_id = ?1 AND quote_id = ?2',
'bind' => [
1 => $info['application_id'],
2 => $info['quote_id'],
]));
$this->view->setVar('object_list', $object_list);
if ($object_list) {
$this->view->setVar('has_files',true);
} else {
$this->view->setVar('has_files',false);
}
}
我还不知道如何检查 $object_list
是否为 EOF,以便我可以更好地设置 has_files
变量。目前它不工作。我如何在控制器和 .volt
视图中做到这一点?
这其实很奇怪。使用 findFirst
或任何其他 ORM 方法 returns false
会失败,但是使用 find
不会。
针对您的情况,一个简单的解决方法是对结果集使用 count
方法:
$test = \Models\Objects::find([
'conditions' => 'is_active = 42'
]);
if ($test->count()) {
print('I have records with is_active = 42');
d($test->toArray());
} else {
print('I do not have any records with is_active = 42');
}