简体   繁体   中英

Calling $this inside Model in Phalcon

I need reanimate an old site, that was made by another programmer a long time ago. The site is built on Phalcon and I don't know which versions of PHP are supported.

I'm seeing many errors like:

Using $this when not in object context

It is triggered because in Models many functions calls core functions of Phalcon like $this->session->get('auth') , but it looks like a new version of PHP doesn't allow it.

How can I fix it without a total rewrite of all models?

Is there any other way to call Phalcon's $this in Model?

Or is it not possible?

If you add variable $di (factory) to your application

you need to write this :

$this->di->session->get('auth');

You are calling a static method, therefore an object has not been created and there IS NO $this.

Static methods are BAD, try and avoid! They're essentially standalone functions hiding inside a class. They're also very annoying to test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM