Welcome Guest, Not a member yet? Register   Sign In
Constructor - Assigning class variables
#1
Question 
(This post was last modified: 05-11-2020, 10:58 PM by jreklund.)

Code:
class Home extends BaseController
{
    var $cache;

    public function __contruct()
    {
        parent::__construct();
        $this->cache = \Config\Services::cache();
    }
    public function reset()
    {
        $this->cache->clean();
    }
}

assume i have create a web cache.

the idea is i dont want to keep assign the same $cache in every method.

So contructor should do the job.

but when i load the page, it shows -> Undefined variable: cache

how to fix my code/this issue?
Reply


Messages In This Thread
Constructor - Assigning class variables - by nmaa3003 - 05-11-2020, 01:38 PM
RE: ci4 constructor not working - by jreklund - 05-11-2020, 10:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB