Moving "if logged in" logic out of header view |
[eluser]Prophet[/eluser]
Hi all. I'm fairly new to CodeIgniter (in fact I'm fairly new to MVC frameworks!) so please let me know if you think any of my methods can be improved. The website I am developing has a navigation bar, as do most websites. In the navigation bar I would like to have an item that, depending on the user's is_logged_in status will either be "Login", "Register", or "My Account". Right now the logic for this is in my header.php view file which is included in all the other views. I have been advised that having presentation logic inside views isn't best practice, but the only other place I can think of putting the logic is in each controller file individually. Is there a way to perform this logic in only one file, and pass the result to the header view? Many thanks in advance, Joseph
[eluser]InsiteFX[/eluser]
Create a MY_Controller then extend all your other controllers from MY_Controller. Place your code into the MY_Controller. MY_Contoller Enjoy InsiteFX
[eluser]Prophet[/eluser]
[quote author="InsiteFX" date="1269498483"]Create a MY_Controller then extend all your other controllers from MY_Controller. Place your code into the MY_Controller. MY_Contoller Enjoy InsiteFX[/quote] Thank you, I hadn't thought of that. Are you hinting that the logic to handle the menu items would be inside the constructor function of MY_Controller, and the sub-controllers would inherit whichever menu value MY_Controller passes?
|
Welcome Guest, Not a member yet? Register Sign In |