php - 在 Zend Framework 中获取选定的行

标签 php database zend-framework fetch

我知道如何从数据库中获取所有结果 我想做的是获取选定的行。 谁能给我一个示例代码。

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;
}

我该如何获取..

这是我的 Controller 对 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 架构非常陌生。 任何帮助将不胜感激。

最佳答案

这里有完整的文档: http://framework.zend.com/manual/1.12/en/zend.db.table.row.html

您需要调用:fetchRow() 方法而不是fetchAll()

关于php - 在 Zend Framework 中获取选定的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14954320/

相关文章:

php - 在 drupal 7.0 中页面加载时将数据库值保存在文本字段中

php - 将单选按钮的选择插入 MySQL

ruby-on-rails - Rails - 电子表格适配器

zend-framework - Zend_Framework : Pass array options to a custom filter

zend-framework - Zend 框架 SEO 技巧

php - 使用包含 GROUP_CONCAT 的 Zend DB 编写子查询

PHP:filter_var 清理是否足够安全?

javascript - 根据表单内的选择显示不同表单的单选按钮

database - CakePHP 和 AJAX 无需刷新页面即可更新数据库

mysql - 用MYSQL查询多表的逻辑