目前我有一個頁面,我通過該俱樂部的id檢索到一個俱樂部的信息。我現在有一個評論框,我想檢索關於該俱樂部的評論,在評論表中我有club_id,並且參數「club_id」被傳入此頁面。目前我正在檢索表格中的所有評論,但我只想要那個俱樂部的評論。一個正確的方向將是偉大的!Zend Framework查詢分貝和getParam
控制器:
class ClubDescriptionController extends Zend_Controller_Action
{
public $auth = null;
public function init()
{
$this->auth=Zend_Auth::getInstance();
}
http://pastebin.com/m66Sg26x
protected function authoriseUser()
{
if (!$this->auth->hasIdentity()) {
$route = array('controller'=>'auth', 'action'=>'index');
$this->_helper->redirector->gotoRoute($route);
}
}
}
型號:
class Application_Model_DbTable_Comments extends Zend_Db_Table_Abstract
{
protected $_name = 'comments';
public function getComment($id) {
$id = (int) $id;
$row = $this->fetchRow('id = ' . $id);
if (!$row) {
throw new Exception("Count not find row $id");
}
return $row->toArray();
}
public function addComment($comment, $club_id) {
$data = array(
'comment' => $comment,
'club_id' => $club_id,
'comment_date' => new Zend_Db_Expr('NOW()'),
);
$this->insert($data);
}
public function deleteComment($id) {
$this->delete('id =' . (int) $id);
}
}
的觀點:
<div id="view-comments">
<?php foreach($this->comments as $comments) : ?>
<p id="individual-comment">
<?php echo $this->escape($comments->comment);?> -
<i><?php echo $this->escape($comments->comment_date);?></i>
</p>
<?php endforeach; ?>
</div>
我意識到我將不得不使用getComment();在我的模型功能,並通過ID查詢,但我越來越困惑於究竟如何?
感謝
你能表現出Application_Model_DbTable_Clubs的代碼?我認爲這與你的問題有關。 – vascowhite 2012-04-24 19:22:38