Not sure whether it's even a Phalcon related issue, though I've never run into this before on other frameworks (or plain php). So maybe you guys faced similar problem before.
Basically I've got a function that is trying to read and decrypt cookies (and then log the user in). It breaks at the last line of below code, when trying to create MongoId of $userId:
public function loginWithRememberMe()
{
$key = \Phalcon\DI::getDefault()->get('crypt')->getKey();
$crypt = new Phalcon\Crypt();
$userId = $crypt->decrypt($this->cookies->get('RMU')->getValue(), $key);
$cookieToken = $crypt->decrypt($this->cookies->get('RMT')->getValue(), $key);
if($userId !== null && $cookieToken !== null)
{
$users = new User();
$user = $users->findById( $userId );
I am able to see the $userId when I echo it, but when passing it to findById it throws following exception:
MongoException: Invalid object ID
- string itself is a valid id, as I have tested it running the query manually
- if I hardcode it inside findById, it works fine
- function is in a library that extends Phalcon\Component
- it is called at the very beginning in my ControllerBase (base of all my controllers)
- cookies are present in browser
- encryption/decryption seems to work fine (using Phalcon\Crypt)
- id in question: 4f20835f97c7142a30000c9b (it is also visible in stacktrace)
Looks to me like a scope issue which I am failing to notice.