[eluser]bookvir[/eluser]
Hi all,
I got an MVC question - I want to know how I am supposed to do something according to MVC architecture and I'm not sure if I'm doing this right.
I'm using a View consisting of some mini views:
- header
- menu
- login form
- page data
- footer
When a user is logged in the overall View is the same, only parts change (*):
- header
- menu *
- login information *
- page data
- footer
Am I supposed to check whether the user has logged in in the controller and then choose an appropriate view (eg. login form - login information)? It implies that i have to use the same code in every controller which uses the same page template (and since roughly the only part that does change in my controllers is really "page data", that would be a lot):
Code:
class A extends Controller {
/* ... */
function stuff()
{
/* ... */
$this->load->view('header');
$this->load->view('menu');
if ($this->session->userdata('logged_in')) {
$this->load->view('logininfo');
}
else {
$this->load->view('loginform');
}
$this->load->view('pagedata');
$this->load->view('footer');
}
}
My current solution is quite different and I suppose it's not really nice. It just doesn't feel nice. I think.
In the controller I just load all the views:
Code:
function stuff()
{
/* ... */
$this->load->view('header');
$this->load->view('menu');
$this->load->view('form');
$this->load->view('pagedata');
$this->load->view('footer');
}
Now in the view "form" I do something (ugly?) like this:
Code:
<?php if ($this->session->userdata('logged_in')) { ?>
CONTENT OF 'LOGIN INFORMATION'
<?php
}
else {
?>
CONTENT OF 'LOGIN FORM'
<?php
}
?>
So, is this wrong? It just seems a simpler solution, having less code (no repeated code in controllers) at the price of "cheating within views". I mean, is this okay with the MVC pattern?
Thanks a lot.