I have a controller with a couple of methods and they all have the same variable within them. I am looking for a way to have them share the same variable. What is the best way to do this?
What I have now:
class Example extends CI_Controller{
public function test{
$variable = "awesome";
}
public function demo{
$variable = "awesome";
}
}
In CodeIgniter 4, we have a folder like app/config/Constant. php so you can define a global variable inside the Constant. php file.
How about...
class Example extends CI_Controller
{
public $variable = "awesome";
public function test()
{
echo $this->variable; // awesome
}
public function demo()
{
echo $this->variable; // awesome
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With