Is this a good approach?? Phil Sturgeon Template Library |
[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.
[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?
[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>
[eluser]NachoF[/eluser]
Ok, this seems to be a better way. http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY
[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.) |
Welcome Guest, Not a member yet? Register Sign In |