【问题标题】:Check if Doctrine results is NULL or empty or hasn't any records检查 Doctrine 结果是否为 NULL 或为空或没有任何记录
【发布时间】:2013-06-10 15:05:24
【问题描述】:

为了向用户显示消息,检查 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

【问题讨论】:

    标签: doctrine symfony-1.4 doctrine-1.2


    【解决方案1】:

    execute() 方法返回一个 DoctrineCollection 对象。 You can use count().

    public function count(  )
    

    获取此集合中的记录数

    返回整数

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-28
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 2020-03-16
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多