Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

a model of the access method modelsManager->createQuery

Notice: Access to undefined property Signup::modelsManager

class Signup extends \Phalcon\Mvc\Model { public function busy_checking($username, $email) {

    $query = $this->modelsManager->createQuery("SELECT * FROM Users WHERE username = :username: OR email = :email:");

    $users = $query->execute(array(
        'username' => $username,
        'email' => $email
    ));

    return count($users);
}


81.1k

"modelsManager" is not a property of Phalcon\Mvc\Model



7.1k

and then how can I use it from the model?



81.1k
Accepted
answer

This is the way:

<?php

class Signup extends \Phalcon\Mvc\Model
{

    public function busy_checking($username, $email)
    {
        $phql = "SELECT * FROM Users WHERE username = :username: OR email = :email:";
        return count($this->getModelsManager()->executeQuery($phql, array(
            'username' => $username,
            'email' => $email
        )));        
    }

}

However, there is a short way:

class Signup extends \Phalcon\Mvc\Model
{

    public function busy_checking($username, $email)
    {
        return Users::count(array(
            "username = :username: OR email = :email:",
            'bind' => array('username' => $username, 'email' => $email)      
        ));
    }

}