Is this a good approach?? Phil Sturgeon Template Library - 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 a good approach?? Phil Sturgeon Template Library (/showthread.php?tid=31059) |
Is this a good approach?? Phil Sturgeon Template Library - El Forum - 06-04-2010 [eluser]NachoF[/eluser] I want my site to show me the name of the user thats using the site on every page.. and its seems to be that it is a little redundant having to send the user as data everytime Im going to use Code: $this->template->build(); Code: $this->template->build("someview", $data); $this->myviewbuilder("someview", $data); and in My_Controller Code: function myviewbuilder($view="",$data="") so now in my layout file I can always use Code: $user I cant think of a better way to do this.. please help. Is this a good approach?? Phil Sturgeon Template Library - El Forum - 06-05-2010 [eluser]falkencreative[/eluser] Couldn't you just set a session variable to store that information? And then request that user data in your view file? Is this a good approach?? Phil Sturgeon Template Library - El Forum - 06-05-2010 [eluser]NachoF[/eluser] Basically what I want is a sidebar div where if the user is logged in it shows his name. otherwise it shows a login form Having to set the user object the way you are sugesting I would have to do something like this in my master view... which doesnt look like very good practice cause its permoring a database query inside the master view Code: <div> Is this a good approach?? Phil Sturgeon Template Library - El Forum - 06-05-2010 [eluser]NachoF[/eluser] Ok, this seems to be a better way. http://philsturgeon.co.uk/news/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY Is this a good approach?? Phil Sturgeon Template Library - El Forum - 06-05-2010 [eluser]falkencreative[/eluser] Seems to me that you could do this: -- when a user logs in, set a session variable storing his name and id Thus, in your sidebar div, you could do something like this: Code: if (isset($this->session->userdata('user_name'))) This way, you minimize database calls. With your code, my impression is that you are checking the database on each page load to find the username, I believe you'll also run into an error if $this->session->userdata('user_id') isn't set and you try to access it (haven't tested it, but that's my impression.) |