dongtaidai0492 2011-12-19 10:54
浏览 38
已采纳

如何将视图放在zend框架中

This is my Controller coding in zend framework

public function homeAction() {

    $storage = new Zend_Auth_Storage_Session();
    $data = $storage->read();
    if (!$data) {
        $this->_redirect('admin/login');
    }
    $this->view->storeid = $data->storeid;
    $iExtStoreId = $data->storeid; // admin storeid

    $db = Zend_Db_Table::getDefaultAdapter();
    $sql = "SELECT storeId FROM stores where extStoreId= '$iExtStoreId' ";

    $result = $db->fetchAll($sql);
    $sStoreId = $result[0]['storeId'];
    if (strlen($sStoreId) >= 32) {
        $sql = "select * from voucherRedemptions where storeId='$sStoreId'";

        $result2 = $db->fetchAll($sql);
    } else {
        $result2 = array();
    }
    echo "<table border='1'>
                        <tr>
                        <th>redemptionId</th>
                        <th>voucherId</th>
                        <th>storeId</th>
                        <th>redemptionTime</th>
                </tr>";

    if (count($result2) > 0) {
        foreach ($result2 as $row) {
            echo "<tr>";
            echo "<td>" . $row['redemptionId'] . "</td>";
            echo "<td>" . $row['voucherId'] . "</td>";
            echo "<td>" . $row['storeId'] . "</td>";
            echo "<td>" . $row['redemptionTime'] . "</td>";
            echo "</tr>";
        }
    } else {
        echo "<tr><td colspan='4'>Data not found </td></tr>";
    }

    echo "</table>";
}

now I want to keep the view code in view folder home.html what i can do ?

  • 写回答

2条回答 默认 最新

  • dongshengli6384 2011-12-19 11:00
    关注

    Don't echo all that stuff in the controller. That's what the view is for.

    After setting all the viewvariables do:

    $this->render('/path/to/home.html');
    

    And print all the stuff there.

    Also note that the Zend Framework has pretty good documentation available.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据