Ok to set userdata session variables in admin controller? |
[eluser]gwerner[/eluser]
I'm setting a couple of session variables to the data array in my Admin_Controller to access in all admin view files. I was going to put in my controllers, but seems redundant to place in each. Another thought was to place them in my header template within my views. Ultimately I think this is the better way to access throughout all my admin pages. Is this a secure/ok way to implement? Code: class Admin_Controller extends MY_Controller { I then have access to the variable in my views via Code: <?php echo $this->data['username']; ?>
[eluser]CodeIgniteMe[/eluser]
The best way if to pass data as variables like instructed on the UserGuide Views because having access to the $this object from the view can create accidental overwriting of the properties of $this or $this itself. therefor violating the MVC model. I am only pertaining to the way you pass the data though. But as long as you know what you are doing, you can bravely experiment.
[eluser]Karman de Lange[/eluser]
Have look at: Code: $this->load->vars($array) Not tried but this might work; Code: $session_data = $this->session->userdata('logged_in'); Code: Username: <?php echo $usernane ?>
[eluser]CodeIgniteMe[/eluser]
[quote author="Karman de Lange" date="1340259175"]Have look at: Code: $this->load->vars($array) Not tried but this might work; Code: $session_data = $this->session->userdata('logged_in'); Code: Username: <?php echo $usernane ?> [/quote] correct, this is a much acceptable solution
[eluser]gwerner[/eluser]
[quote author="Karman de Lange" date="1340259175"]Have look at: Code: $this->load->vars($array) Not tried but this might work; Code: $session_data = $this->session->userdata('logged_in'); Code: Username: <?php echo $usernane ?> [/quote] This works like a charm. [quote author="CodeIgniteMe" date="1340258493"]The best way if to pass data as variables like instructed on the UserGuide Views because having access to the $this object from the view can create accidental overwriting of the properties of $this or $this itself. therefor violating the MVC model. I am only pertaining to the way you pass the data though. But as long as you know what you are doing, you can bravely experiment.[/quote] Thanks for pointing this out. Makes perfect sense. I didn't have a good feeling about doing it that way, but was the only way I was getting it to work without the above solution. Thanks again.
[eluser]CodeIgniteMe[/eluser]
Good to know ![]() Again, you can experiment on things as long as you know and understand what you are doing. Experimenting on things is a sign of good development health. |
Welcome Guest, Not a member yet? Register Sign In |