Reynier
Reynier

Reputation: 2478

Check if Doctrine results is NULL or empty or hasn't any records

Which is the right way to check if Doctrine query result is empty or hasn't values in order to show a message to users? I've this code:

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

And in my view I'm checking as follow:

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

But doesn't work because $sdriving_emisors always has content, so any help? PS: I'm working with Symfony 1.4.20

Upvotes: 1

Views: 6660

Answers (1)

glerendegui
glerendegui

Reputation: 1507

The execute() method returns an DoctrineCollection Object. You can use count().

public function count(  )

Gets the number of records in this collection

Returns integer

Upvotes: 5

Related Questions