Global variable in overrided Controller |
Any public property in the controller is easily accessed just about anywhere. Take the property "$data" in the following example.
PHP Code: Class Welcome extends CI_Controller You can get the value of $data everywhere in the controller using $this->data. It's also available anywhere you can get a reference to the controller. In models, you can still use $this. Here's a proof of concept. (It's dumb, I know. But it demos the point.) PHP Code: Class Welcome extends CI_Controller Model PHP Code: class Test_model extends CI_Model The view PHP Code: <!DOCTYPE html> Send a browser to example.com/welcome/sayhi/Dave and the screen displays "Hello Dave" If you want to get at the controller from a custom library you have to do the same thing that the core libraries do - use get_instance(); You've probably already read about that here. |
Messages In This Thread |
Global variable in overrided Controller - by imabot - 10-18-2018, 05:06 AM
RE: Global variable in overrided Controller - by vincent78 - 10-18-2018, 05:41 AM
RE: Global variable in overrided Controller - by dave friend - 10-18-2018, 06:45 AM
|