Apart view files or session check on one view file?
I'm making a profilesystem with Codeigniter 2.0.1 which uses the MVC pattern. Now I want a profilepage for public users who are not logged in and a one for users who are logged in. The profilepage where users are logged in contains other options than the other page. Should I make an apart view file for each page or sh开发者_运维百科ould I do a session check on one page? I'm asking this because I read that checks shouldn't be in view file.
My question was if I could do some session checks on a view file... For example: When an users visits its own profile, i'll give it a link to go to the settings page
if (this->session->userdata('uid') == 20) {
<a href="edit_profile">Edit my profile</a>
}
Is this against the MVC model and should I do this session checks in the controller and make apart view files?
If I'm understanding you right, you need to look at whether this person visiting you site is logged in and has permission to view that page.
You'd do this in your controller, and it would go something along the lines of:
if(this->session->userdata('logged_in')) {
$this->load->view('profile_private');
} else {
$this->load->view('profile_public');
}
Though obviously there's a bit more to it than that.
Take a look at Codeigniter's sessions class http://ellislab.com/codeigniter/user_guide/libraries/sessions.html
Also user authentication: http://www.google.co.uk/search?q=codeigniter+authentication
And of course there's already already answers on SO: User authentication with CodeIgniter
Hope this helps.
精彩评论