Can someone please show me how to do this basic thing using Zend Framework MVC?
I’m looping over the timestamp data and populating my table that way. i don’t understand how I would pull my presentation HTML from this loop and stick it in the view? Any help would be greatly appreciated!
<table>
<?php
$day = date("j");
$month = date("m");
$year = date("Y");
$currentTimeStamp = strtotime("$year-$month-$day");
$numDays = date("t", $currentTimeStamp);
$counter = 0;
for($i = 1; $i < $numDays+1; $i++, $counter++)
{
$timeStamp = strtotime("$year-$month-$i");
if($i == 1)
{
// Workout when the first day of the month is
$firstDay = date("w", $timeStamp);
for($j = 0; $j < $firstDay; $j++, $counter++)
echo "<td> </td>";
}
if($counter % 7 == 0) {
echo "</tr><tr>";
}
echo "<td>" .$i . "</td>";
}
?>
</table>
I’m wanting to turn the above code into functions, but the HTML is throwing me off.
******Edited**** (mvc solution added)
Don’t clutter your code with unnecessary functions, partials, etc. Why bother with HTML from the start, when you can create your data, then transform it into an HTML table? Here’s the MVC sample (the following code suppose a one module project called ‘default’, modify accordingly if the project is module based) :
[listing 1] application/controller/IndexController.php
[listing 2] application/models/Calendar.php
[lisging 3] application/view/scripts/index/index.phtml
[listing 4] application/view/helpers/CalendarTable.php
With this code, you can even set exactly what you want within the
$calarray before callingarray_chunkon it. For example,$cal[] = $dayHtml . '<a href="#">more</a>';This also follow true MVC as data (in
Default_Model_Calendar) and view (inDefault_View_Helper_CalendarTable) are completely separated, giving you the freedom to use any other model with the view helper, or simply not using any view helper with your model!