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/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How do I define a global variable after the Codeigniter instantiation? (/showthread.php?tid=79999)



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.