We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon Model not accepting variable(?)

I have a trouble when i try to verify if a user exists in the database.

$login = $this->cookies->get('login');

$loggedinas = $login->getValue();

$user = Users::findFirstByUsername($loggedinas)

This returns:

PHP Notice: Trying to get property of non-object in /public_html/app/views/charactersheets/create.phtml on line 27, referer: localhost/charactersheets

However if i use this:

$user = Users::findFirstByUsername("pentacore")

it works, and i've checked so that the cookie contains the right username with var_dump() which returned pentacore so... what could be the problem?



98.9k
Accepted
answer
edited Oct '14

It could be that cookie's decryption adds extra trailing spaces so you have probably to do:

$login = $this->cookies->get('login');
$loggedinas = trim($login->getValue());
$user = Users::findFirstByUsername($loggedinas)


2.8k

thank you, that solved it