set a global variable in codeigniter function
I have a codeigniter web application which开发者_开发知识库 has two buttons guest or user. The whole application uses the same pages whether you are a guest or user, but if you click the user button I want it to bring the user to a login page, I can do that, but I need to be able to set a global variable, only if the user uses the user/login button.
I would set some sort of session data when processing the form submission for the user login. Something like:
$this->session->set_userdata(array('is_user' => TRUE));
That is as close as you'll get to setting global data.
Is your question similar to this one? Access Codeigniter data variables in function inside a view
In the strict sense of global
, CodeIgniter doesn't allow user-defined globals to prevent it's own framework variables to be overwritten by the user.
I tried several things within the view, passing variables from controller to view, but it's never assigned to $GLOBALS
.
You can use session or cookies to store your data if you really need to.
精彩评论