检查原则结果是否为空或为空或没有任何记录



检查Doctrine查询结果是否为空或没有值以便向用户显示消息的正确方法是什么?我有这样的代码:

public function executeIndex(sfWebRequest $request) {
        $this->sdriving_emisors = Doctrine_Core::getTable('SdrivingEmisor')->createQuery('a')->execute();
}

在我看来,我检查如下:

<?php if (!empty($sdriving_emisors)): ?>
  // show records
<?php else: ?>
  // show message
<?php endif; ?>

但不工作,因为$sdriving_emisors总是有内容,所以有帮助吗?PS:我正在使用Symfony 1.4.20

execute()方法返回一个DoctrineCollection Object。你可以使用count()

public function count(  )

获取此集合中的记录数

返回整数

最新更新