db error

when i want to use findfirst i got this error:

Fatal error: Call to undefined method User::findFirst() in C:\wamp\www\soscial\app\controllers\LoginController.php on line 78

$user = User::findFirst("email='$email' AND password='$password' AND show_admin='1'");

this is my code. and i have an model User.php

how can i solve this?


Check whether the autoloader works.

Also does your user class extend model ?


loader is working , and yes class User extends \Phalcon\Mvc\Model

. But there ar smt i think , when i delete the example database password there ar no error about database ?


i dont know about what the problem but when i change User class to Users it's solved ?


i ask so much question sorry but i want to learn this

i have users table and on it has "usertype" column. and on "usertypes" table. on usertype there ar a row like that ; id = 1, name = admin, and on users table there ar row id = 1 usertype = 1 (i hope i can explain it)

on the login i want to findFirst (email = $email, $password = $password and name = admin(its from user_type) ) how can i do that

(i mean exactly : select * from users inner join usertypes on usertypes.id = users.usertype where email = $email and password = $password and usertypes.name = 'admin')

so thanks


Something like this must work, remember define the relationships between both models in the class definitions:

$user = $this->modelsManager->createBuilder() 
    ->where('Users.email = :email:')
    -andWhere('Users.password = :password:')
    ->execute(array('email' => $email, 'password' => $password))


how can i write the sql query after that to test ? (i mean get last query)