phpphalconeofphalcon-orm

Phalcon PhP - is there an EOF for model::find


I'm writing a piece of code and in it I would like to know if the result of a find if empty or not. Here is my piece of code:

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);
    }
}

What I don't know yet if how to check if $object_list is EOF so I can set the has_files variable better. Currently it is not working. How can I do that in a controller and in a .volt view?


Solution

  • This is pretty strange actually. Using findFirst or any other ORM method returns false on fail, however using find does not.

    A simple workaround in your case would be to use the count method on the result set:

    $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');
    }