Note that there are some explanatory texts on larger screens.

plurals
  1. POInvalid argument supplied for foreach() in index.phtml in Zend
    primarykey
    data
    text
    <p><strong>The code for index.phtml as follows:</strong></p> <pre><code>&lt;?php foreach ($this-&gt;entries as $entry): ?&gt; &lt;?php echo $this-&gt;escape($entry-&gt;email) ?&gt; &lt;br&gt;&lt;/br&gt; &lt;?php echo $this-&gt;escape($entry-&gt;comment) ?&gt; &lt;?php endforeach ?&gt; </code></pre> <p><strong>The code for indexAction() in IndexController:</strong></p> <pre><code>public function indexAction() { $guestbook = new Application_Model_HRModel(); $view = new Zend_View(array('scriptPath' =&gt;'C:/Users/398853/Documents/NetBeansProjects/PhpProject3/application/views/scripts/index')); $view-&gt;entries = $guestbook-&gt;fetchAll(); echo $view-&gt;render('index.phtml'); } </code></pre> <p><strong>The code for fetchAll() in Application_Model_HRModel:</strong></p> <pre><code> public function fetchAll() { $entry = new Application_Model_HRMo(); $resultSet = $this-&gt;getDbTable()-&gt;fetchAll(); $entries = array(); foreach ($resultSet as $row) { $entry-&gt;setId($row-&gt;id); $entry-&gt;setEmail($row-&gt;email); $entry-&gt;setCreated($row-&gt;created); $entry-&gt;setComment($row-&gt;comment); $entries[] = $entry; } return $entries; </code></pre> <p>} I have 3 entries i.e. 3 rows in my databse table . But When i request the url as <a href="http://localhost:8888/Index" rel="nofollow">http://localhost:8888/Index</a> it says Warning: Invalid argument supplied for foreach() in C:\Users\39885Documents\NetBeansProjects\PhpProject3\application\views\scripts\index\index.phtml on line 54 and then display last row's entry 3 times.I think problem occurs because at first it executes index.phtml and without executing indexAction()(which further executes fetchAll()) $entries will not an array Thats Why at first it gives above stated warning. Now tell me how to start execution from indexAction() then come at index.phtml so that $entries would be an array.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload