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.

Trying to call method get on a non-object

Hi, I'm trying to write a JWT library with Phalcon 3 and i have some problems when I try to set a cookie with the generated token.

¿Can anyone help me, please?

This is my code:




    $di->setShared('cookies', function () {
        $cookies = new Cookies();
        return $cookies;

    $di->set('gauth', function(){
        $gauth = new gAuth();
        return $gauth;


    public function authAction(){


    use Phalcon\Crypt;
    use Phalcon\Http\Response\Cookies;

    class gAuth
        public    $token;
        protected $cookie;
        private   $secret;
        private   $crypt;

        public function __construct()
            $this->secret = '************;
            $this->crypt = new Crypt();
            $this->cookie = new Cookies();

        public function storeToken()
        // here I get the error: Trying to call method get on a non-object
        $this->cookie->set('tkn', '***', time() + 3600, '/', null, '', null)->send();

The error I get is: RuntimeException: Trying to call method get on a non-object


Instead of creating cookies and crypt use already one from Di which you registered.