Basic PHP Design Questions
Posted: Wed May 13, 2009 9:18 pm
I've mainly used Ruby on Rails in the past, but I'm moving to PHP for performance reasons.
My first question is about design templates. So far I've seen two ways to do it, making PHP files for the header, menu, footer, etc. and using include, or using Smarty. Are there any other common ways I should know about?
My second question is about the use of echo. Let's say I want to loop through a set of data and render some divs for each one. In RoR, it could be done like this:
But in PHP, the only way i know to do it would be like this:
Since it's within PHP code, do I always need to use echo to render HTML? Or is there a cleaner way, such as the RoR way?
Thanks!
My first question is about design templates. So far I've seen two ways to do it, making PHP files for the header, menu, footer, etc. and using include, or using Smarty. Are there any other common ways I should know about?
My second question is about the use of echo. Let's say I want to loop through a set of data and render some divs for each one. In RoR, it could be done like this:
Code: Select all
<% @data.each do |d| %>
<div id="some_div">
<p>blah blah</p>
</div>
<% end %>
Code: Select all
foreach ($data as $d)
{
echo "<div id ='some_div'>";
echo "<p>blah blah</p>";
echo "</div>";
}
Thanks!