CodeIgniter Forums
How do I define a global variable after the Codeigniter instantiation? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: How do I define a global variable after the Codeigniter instantiation? (/thread-79999.html)



How do I define a global variable after the Codeigniter instantiation? - castle - 08-31-2021

Hi,

This post recommends putting global variables in
Code:
/application/config/constants.php
however, that too early. I need the global variable to be assigned after the controller instantiation. Is there a way of doing that?

Cheers



RE: How do I define a global variable after the Codeigniter instantiation? - InsiteFX - 08-31-2021

You would need to either place it in the BaseController or create a library for it using static variable.
Or  use Events, see below:

CodeIgniter 4 User Guide - Events


RE: How do I define a global variable after the Codeigniter instantiation? - castle - 08-31-2021

(08-31-2021, 04:04 AM)InsiteFX Wrote: You would need to either place it in the BaseController or create a library for it using static variable.
Or  use Events, see below:

CodeIgniter 4 User Guide - Events

Thanks, but I'm using CI 3


RE: How do I define a global variable after the Codeigniter instantiation? - InsiteFX - 09-01-2021

Then you can use a hook lookup hooks in the user guide.