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 loo开发者_如何学运维p 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
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.....?
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'];
}
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 ?>
精彩评论