在 zend 框架中的特定列中显示数组数据

show array data in specific column in zend framework

我 3 天前开始学习 Zend,但卡住了。我在 view.phtml

中有一个 table 样本 table
<thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Email</th>
                <th>Address</th>
                <th>Status</th>                   
            </tr>
        </thead>

并在 model.php

public function listallemail() {
        $db = $this->getDefaultAdapter();
        $query = $db->select()
                ->from('members','email');
        return $db->fetchAll($query);
    }

现在我已经列出了来自 mysql 数据库的所有电子邮件,我只想插入到 <th>Email</th> 中,而另一列留空。谁能建议我这样做的方法

您应该return 将数据传递给控制器​​,然后将数据传递给视图。由于您没有提供任何额外的详细信息,我将猜测您的应用程序结构

控制器

class Default_IndexController extends Zend_Controller_Abstract
{ 
    public function viewAction()            
    {                                                           

        ...
        $this->view->emaildetails = $modelObj->listallemail();
    }

}

型号

public function listallemail() {
        $db = $this->getDefaultAdapter();
        $query = $db->select()
                ->from('members','email');
        return $db->fetchAll($query);
    }

view.phtml

<thead>
    <?php foreach($this->emaildetails as $email):?>
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th><?php echo $email->email ?></th>
        <th>Address</th>
        <th>Status</th>                   
    </tr>
    <?php endforeach; ?>
</thead>