![]() |
is this ok in a view? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: is this ok in a view? (/showthread.php?tid=11019) |
is this ok in a view? - El Forum - 08-22-2008 [eluser]Fenix[/eluser] With the MVC pattern, is it ok to put something like this in a view? Code: if logged in More specifically, is it ok to actually check the session for things like this right in the view? Something like: Code: if ($this->session->userdata('id') >0) is this ok in a view? - El Forum - 08-22-2008 [eluser]LuckyFella73[/eluser] I think, if the status logged in or not would only change a small part of the view it's no problem. Maybe it would be more strict to check the status in the controller, store the link (the HTML part) in a variable and just echo the variable in the view. Would be a bit more flexible. is this ok in a view? - El Forum - 08-22-2008 [eluser]Adam Griffiths[/eluser] I do this inside the controller. It would be best to put it in a controller, and put the user details/logout link etc in one view file, and the login form in another view file. That way it would be easier to find things and change them at a later date. is this ok in a view? - El Forum - 08-22-2008 [eluser]fesweb[/eluser] Even better? Create a function in a/the model which checks the login status and writes the link. This is probably horribly wrong to do... Code: function check_login() { Code: function check_login() { Code: $this->load->view($this->your_model->check_login()); is this ok in a view? - El Forum - 08-22-2008 [eluser]Fenix[/eluser] Ok, I was just thinking that the header view (where the link would go) is going to be on every page so it would get annoying having to check the login status every time you load a view... something like... Code: $data['logstatus'] = $this->session->userdata('id'); |