我知道如何从数据库中获取所有结果我想要做的是获取选定的行。谁能给我一个示例代码。
public function getAllAddresses()
{
$dbTable = new Application_Model_DbTable_User();
$result = $dbTable->fetchAll();
$addresses = array();
foreach ($result as $row) {
$address = new Application_Model_User();
$address->setuserId($row->userId)
->setuserName($row->userName)
->setaddressLine1($row->addressLine1)
->setaddressLine2($row->addressLine2)
->setaddressLine3($row->addressLine3)
->settelephone($row->telephone);
$addresses[$row->userId] = $address;
}
return $addresses;
}
我该怎么做。。
这是我对 fetchAll 的控制器调用
public function indexAction()
{
// action body
$addressMap = new Application_Model_UserMapper();
$addresses = $addressMap->getAllAddresses();
$this->view->addresses = $addresses;
}
如何调用 fetch 方法?
这是我的看法
<?php if (isset($this->addresses)) : ?>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Street</th>
<th>City</th>
<th>Town</th>
<th>Telephone</th>
</tr>
</thead>
<tbody>
<?php
foreach ($this->addresses as $userId => $address) {
$trow = '<tr>';
$s = $address->getuserId();
$trow .= '<td>'. $address->getuserId() .'</td>';
$trow .= '<td>'. $address->getuserName() .'</td>';
$trow .= '<td>'. $address->getaddressLine1() .'</td>';
$trow .= '<td>'. $address->getaddressLine2() .'</td>';
$trow .= '<td>'. $address->getaddressLine3() .'</td>';
$trow .= '<td>'. $address->gettelephone() .'</td>';
$trow .= '<td><a href="Index?id='. $s .'">Edit</a></td>';
$trow .= '</tr>';
print $trow;
}
?>
</tbody>
</table>
<?php else : ?>
<p>Address not found</p>
<?php endif; ?>
我对 Zend 和 MVC 架构非常陌生。任何帮助将不胜感激。