[eluser]thePiet[/eluser]
Case:
I have a simple website with some registration and login stuff. No big deal. I'm just focussing on the art of MVC here :-)
For this website, I'm using one view, because the layout is always the same. No I'm facing one difficulty:
The view, simplyfied:
Code:
<html>
<body>
<div>
<h1>Login</h1>
<form>
<input type="text" name="username" />
<input type="password" name="password" />
</form>
</div>
</body>
</html>
So far, so good. But, now the user logs in, and ofcourse I do not want to show the login-div again, but some kind of a "Hello $user" thingy. And that's the problem: how do I generate this HTML correctly, depending on the log-in state of the user?
I can do something like this:
View, simplyfied:
Code:
<html>
<body>
<div>
<?php echo $login_html; ?>
</div>
</body>
</html>
Where $login_html is passed via the controller (which gets it's data by some models). $login_html than can be something like
Code:
<h1>Login</h1>
<form>
<input type="text" name="username" />
<input type="password" name="password" />
</form>
Or, when the user is logged in:
Code:
<h1>Welcome, dude!</h1>
<a href="http://somesite/logoff">Log off</a>
But, I think that's ugly, since no HTML code should sit in Models / Controllers ? Or am I completely wrong?
Kind of hard to explain, but I hope you guys understand me :lol: !
Thanks