Header / Footer for loggedin user vs not loggedin user
Just checking开发者_开发百科 how to implement this - the different header/footer views between the different user states. on my site i have 4 different header/footer types. one for loggedin users, one for non loggedin users, one for blocked users and one for the error pages.
So the question is: Do i need 4 different php files for each header/footer and use conditional logic based on active page/user session to load the header/footer OR do i only have 1 header/footer file and it can dynamically pull in the content based on active page/session - which in essence means all business logic for these different types will be in 1 file vs 4 files.
This is just a matter of preference, there isn't anything wrong with having 1 header/footer and conditionally displaying your content, isn't really much different than having 4 files, so long as your logic is sound.
I tend to always error on the side of organization so I would seperate each situation out with their own folder and just structure it like so...
application
|
|...
|
|_views
|
|_user
| |_header.php
| |_footer.php
|
|_blocked
| |_header.php
| |_footer.php
|
|_error
| |_header.php
| |_footer.php
|
|_public
|_header.php
|_footer.php
This way you can specify in the view load which header you want via the path
$this->load->view('user/header');
and it is very obvious to anyone looking at this out of context to tell what you are doing compared to
$this->load->view('error/header');
And for the logic of knowing which one to load, all of that needs to be determined in the controller. You should not be making those decisions in your view.
精彩评论