• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to comply with the MVC model

#1
[eluser]Matt Bausch[/eluser]
But I have a small piece on which I'm stuck. My goal is that I can use my standard_view.php from most of my controllers. It has a function that builds the page based on parameters sent to it from the controller ($title,$head,$body). But there's one section where I want to A) display the user's name and a link to point to a jquery function to log out or B) just show a link that points to a jquery function to log back in. Since all my login information is based on CI's session, I can't reference it from a view. I guess my real question is, where does one put stuff like that so I don't have to write extra code every time I want a page with my login box displayed.

#2
[eluser]Jondolar[/eluser]
Create a variable in your $data array that sets the current state (logged in or not). Then, in your view, you can wrap the different areas in an "if" statement and check that data array element to decide if you should display one block or another. It does not break MVC to have display logic in your view.

#3
[eluser]Dam1an[/eluser]
It wouldn't be needed in this case, but if you're views are complex and you don't want the extra if/else in the view, you could do the check in the controller, and load the view based on that


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.