Vinay
Vinay

Reputation: 267

How to show data on view

I am new in zend framework .I want to show record on view . But I got an error to showing data .Please help. Thanks in advance ........

when i use foreach loop to show record

<?php foreach($this->fetchedData as $showData  ){ ?>

 <td><?php    echo $showData['name'];?></td>
   <td><?php  echo $showData['address'];?></td>

showing error as : invalid statement used in foreach

Upvotes: 3

Views: 224

Answers (3)

Pushpendra
Pushpendra

Reputation: 4382

This might be the reason :

Your $this->fetchedData may not contain data. And the foreach loop may not be able to handle it......

Try this code :

<?php
$data = $this->fetchedData;
if(isset($data))
{
?>

<?php foreach($this->fetchedData as $showData  ){ ?>

    <td><?php    echo $showData['name'];?></td>
    <td><?php  echo $showData['address'];?></td>
<?php
    }
}
?>

Let me know if you still face the problem.....?

Upvotes: 9

DarkLeafyGreen
DarkLeafyGreen

Reputation: 70416

Maybe you should start learning the MVC basics of zend framwork first. There is a great tutorial series on youtube starting with Zend Framework 1.8 tutorial 1 MVC basics.

More tutorials on http://www.zftutorials.com/.

Programmers Reference Guide Zend Framework & MVC Introduction


To solve your specific problem you should give us your code and point out the error.


Looping through an associative array you have to use http://php.net/manual/en/control-structures.foreach.php

foreach (array_expression as $key => $value)
    statement

so

 foreach($this->fetchedData as $key => $value) {
    echo $value['names'].' and '. $value['addresses'];
 }

Upvotes: 6

James C
James C

Reputation: 14149

In the controller pass your data to the view by using something like:

$this->view->foo = 'bar';

and then in the view you can access it like:

<?= $this->foo ?>

Upvotes: 3

Related Questions