我正在写一段代码,在这段代码中,我想知道如果发现结果为空与否。下面是我的代码:
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方法在失败时返回false
,但是使用find
不会。
count
方法:
$test = ModelsObjects::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');
}