Is there a standard way to handle design (CSS) seperate from conditionals in PHP?
I've been working with a developer on a web-based application. I have some experience with html and css mainly, and now that the heavy lifting is done, I'm wanting to start improving the design elements of the program (I know that is NOT the ideal situation, and in a perfect world, all design elements would have been considered from the beginning-but those of you that work on projects know that it doesn't always go that way :-D )
I'm curious if there is a "standard" way that css and general layout structure is handled when working with extensive PHP conditionals. Here is an example of one area of our page:
$print_data .= '<p><b>My subscription:</b> ';
if($period3=="1 M") {
$print_data .= "$".$amount3." a month.<br />";
$print_data .= "<b>Billing date:</b> Monthly on the " . date("jS", $subscr_effective_date_string开发者_开发技巧) .".<br /><br /><b>Modification Options:</b><br />";
$print_data .= '<input type="button" value="$75 every 6 months" onclick="#" /><br />
<input type="button" value="$135 every 12 months" onclick="#" /><br /><br />';
}
elseif($period3=="6 M") {
$print_data .= "$".$amount3." every 6 months.<br />";
$print_data .= "<b>Billing date:</b> Every 6 months on " . date("m/d", $subscr_effective_date_string) ." and " . date("m/d",$subscr_effective_date_add_6mo_string) .".<br /><br /><b>Modification Options:</b><br />";
$print_data .= '<input type="button" value="$14 a month" onclick="#" /><br /><input type="button" value="$135 every 12 months" onclick="#" /><br /><br />';
}
elseif($period3=="1 Y") {
$print_data .= "$".$amount3." every year.<br />";
$print_data .= "<b>Billing date:</b> Yearly on the " . date("m/d", $subscr_effective_date_string) .".<br /><br /><b>Modification Options:</b>";
$print_data .= '<input type="button" value="$14 a month" onclick="#" /><br /><input type="button" value="$75 every 6 months" onclick="#" /><br /><br />';
}
$print_data .= '<input type="button" value="Unsubscribe" onclick="#" /></p>';
So in short, I'm wanting to contain the above in a <ul>
and then have each conditional be a separate <li>
group that will populate the <ul>
depending on the condition.
Is this sort of thing just usually all handled in-line, or what?
Thanks! Joel
Uf, that's ugly. That's pretty much the reason web development has been moving to a Model-View-Controller (MVC) approach over the last few years. Ideally your presentation markup (the html tags in your soup above) would be in one file and the logic that populates it in another file. One of the most common ways to do this in PHP is to use the Smarty templating engine.
In the interim, at the very least, the code above should be cleaned up: figure out the values for $amount3 and the text that goes on the billing input button and then just output the HTML in one place, rather than repeating it for each case (and it would be nice to use sprintf instead of jamming the strings together for cleanliness and a bit of added security).
精彩评论