嘿,我有 3 个实例供管理员用户显示评论、用户和俱乐部。目前我正在努力让他们显示用户和俱乐部工作正常,但评论并不奇怪,因为对于所有这些我都使用相同的代码但分别替换了变量。
评论型号:
<?php
class Application_Model_DbTable_Comments extends Zend_Db_Table_Abstract
{
protected $_name = 'comments';
public function getComments($id) {
$id = (int) $id;
$row = $this->fetchRow('id = ' . $id);
if (!$row) {
throw new Exception("Count not find row $id");
}
return $row->toArray();
}
}
AdminViewCommentsController:
<?php
class AdminViewCommentsController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$this->view->assign('title', 'Admin - View Comments');
$this->view->headTitle($this->view->title, 'PREPEND');
$comments = new Application_Model_DbTable_Comments();
$this->view->comments = $comments->fetchAll();
}
}
最后是视图:
<table>
<th>Comment</th>
<th>Date</th>
<th></th>
<?php foreach($this->comments as $comments) : ?>
<tr>
<td><?php echo $this->escape($comments->comment);?></td>
<td><?php echo $this->escape($comments->date);?></td>
<td><a href="#">Delete!</a></td>
</tr>
<?php endforeach; ?>
</table>
我曾多次尝试重新输入这些内容,但某处出了点问题,我不知道它会是什么。
谢谢