Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 936839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:22:38+00:00 2026-05-15T21:22:38+00:00

Can someone please show me how to do this basic thing using Zend Framework

  • 0

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>&nbsp;</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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:22:39+00:00Added an answer on May 15, 2026 at 9:22 pm

    ******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

    class IndexController extends Zend_Controller_Action {
       public function indexAction() {
          $this->view->calData = new Default_Model_Calendar('2010-07-17');
       }
    }
    

    [listing 2] application/models/Calendar.php

    class Default_Model_Calendar {
       /* @var Zend_Date */
       private $_date;
       /* @param Zend_Date|string|int $date */
       public function __construct($date) {
          $this->_date = new Zend_Date($date);
       }
       /* @return Zend_Date */
       public function getTime() {
          return $this->_date;
       }
       public function getData() {
          // normally, fetch data from Db
          // array( day_of_month => event_html, ... )
          return array(
             1 => 'First day of month',
             4 => '<span class="holiday">Independence Day</span>',
             17 => '<img src="path/to/image.png" />'
             //...
          );
       }
    }
    

    [lisging 3] application/view/scripts/index/index.phtml

    echo $this->calendarTable($this->calData);
    

    [listing 4] application/view/helpers/CalendarTable.php

    class Default_View_Helper_CalendarTable extends Zend_View_Helper_Abstract {
       private $_calData;
       public function calendarTable($calData = null) {
          if (null != $calData) {
             $this->_calData = $calData;
          }
    
          return $this;
       }
    
       public function toString() {
          $curDate = $this->_calDate->getTime();
          $firstDay = clone $curDate();  // clone a copy to modify it safely
          $firstDay->set(Zend_Date::DAY, 1);
    
          $firstWeekDay = $firstDay->get(Zend_Date::WEEKDAY);
          $numDays = $curDate->get(Zend_Date::MONTH_DAYS);
    
          // start with an array of empty items for the first $firstweekDay of the month
          $cal = array_fill(0, $firstweekDay, '&nbsp;');
          // fill the rest of the array with the day number of the month using some data if provided
          $calData = $this->_calData->getData();
          for ($i=1; $i<=$numDays; $i++) {
             $dayHtml = '<span class="day-of-month">' . $i . '</span>';
             if (isset($calData[$i])) {
                $dayHtml .= $calData[$i];
             }
             $cal[] = $dayHtml;
         }
    
         // pad the array with empty items for the remaining days of the month
         //$cal = array_pad($cal, count($cal) + (count($cal) % 7) - 1, '&nbsp;');
         $cal = array_pad($cal, 42, '&nbsp;');   // OR a calendar has 42 cells in total...
    
         // split the array in chunks (weeks)
         $calTable = array_chunk($cal, 7);
         // for each chunks, replace them with a string of cells
         foreach ($calTable as & $row) {
            $row = implode('</td><td>', $row);
         }
         // finalize $cal to create actual rows...
         $calTable = implode('</td></tr><tr><td>', $calTable);
    
         return '<table class="calendar"><tr><td>' . $calTable . '</td></tr></table>';
       }
       public function __toString() {
          return $this->__toString();
       }
    }
    

    With this code, you can even set exactly what you want within the $cal array before calling array_chunk on it. For example, $cal[] = $dayHtml . '<a href="#">more</a>';

    This also follow true MVC as data (in Default_Model_Calendar) and view (in Default_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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 515k
  • Answers 515k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Where are you running the command from? You need to… May 16, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer Well, that suggests you've not got all the jar files… May 16, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer Try using lazy on your regular expression: ##[\S\s]+?## This will… May 16, 2026 at 6:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Given the example below, can someone please show me how this could be called?
can someone please show me documentation on this method? i have the following line:
Can someone please tell me how I can get the changeset number, the current
I set up this fiddle to show how all browsers render the red pieces.
First post, please be kind. NOTE: I have reviewed entry #20856 (how to implement
This is what I need to do- I have this equation- Ax = y
I saw a java function that looked something like this- public static<T> foo() {...}
I'm getting this error when dealing with a number of classes including each other:
All the generated webservice-stubs from our backend have an equals-method similar to this one:
Pretty much all the apps I use on a regular basis implement this 'seemly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.