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 "user_type" column. and on "user_types" table. on user_type there ar a row like that ; id = 1, name = admin, and on users table there ar row id = 1 user_type = 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 user_types on user_types.id = users.user_type where email = $email and password = $password and user_types.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)