Welcome Guest, Not a member yet? Register   Sign In
Best way to parse HTML
#1

[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>
&lt;form&gt;
&lt;input type="text" name="username" /&gt;
&lt;input type="password" name="password" /&gt;
&lt;/form&gt;
</div>

&lt;/body&gt;

&lt;/html&gt;

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:
&lt;html&gt;

&lt;body&gt;

<div>
&lt;?php echo $login_html; ?&gt;
</div>

&lt;/body&gt;

&lt;/html&gt;

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>
&lt;form&gt;
&lt;input type="text" name="username" /&gt;
&lt;input type="password" name="password" /&gt;
&lt;/form&gt;

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


Messages In This Thread
Best way to parse HTML - by El Forum - 07-10-2009, 08:32 AM
Best way to parse HTML - by El Forum - 07-10-2009, 09:37 AM
Best way to parse HTML - by El Forum - 07-10-2009, 09:43 AM
Best way to parse HTML - by El Forum - 07-10-2009, 12:15 PM
Best way to parse HTML - by El Forum - 07-11-2009, 08:50 AM
Best way to parse HTML - by El Forum - 07-13-2009, 01:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB