Welcome Guest, Not a member yet? Register   Sign In
How use controller property after requests

How we can endure a state of a controller property after a request in CodeIgniter version 4. For example, imagine that $a is a complex object:

/ the controller complains that the variable $a must not be accessed before initialization
class Example extends BaseController
    private int $a;

   public function index()
       $this->a = 7;
      return view('welcome');

   public function checkVariable()
      // the code igniter complains that $a must not be accessed before initialization, but it was when index() was called

Some other languages we have something to sustain the state of those variable. What we have on CodeIgniter? Are there some helper to import to do that for us?

Thanks in advance.

(This post was last modified: 05-05-2020, 07:19 AM by danielsonsilva.)

I found the solution using sessions.
I can add $this->session = \Config\Services::session(); into BaseController
Then, in the end of every method on my controller, I can save the state of $a into the session and in the begin I can get that state and assign into the controller property.

Theme © iAndrew 2016 - Forum software by © MyBB