How to access protected controller attributes from views - 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: How to access protected controller attributes from views (/showthread.php?tid=36332) |
How to access protected controller attributes from views - El Forum - 11-28-2010 [eluser]kimp[/eluser] I have several views which show additional information if the user is an admin. These views include the following code: Code: <?if ($this->session->userdata('userType') == 'Admin'): ?> I have been trying to shorten this by setting a protected attribute in the controller, and testing this attribute (instead of the session userdata). The view code would then be something like: Code: <?if ($this->is_admin):?> When I do this however I'm receiving the error message Undefined property: CI_Loader::$is_admin. How can I make the controller's protected attributes available to the views (without explicitly passing them as part of the content array)? Or should I just make the attributes public? Any assistance appreciated! |