我已經實現了參考指南中的留言簿示例,現在正試圖通過編輯功能來擴展它。Zend框架:方法「getDbTable」不存在,並沒有被困在__call()
我已將此添加到GuestbookController:
public function editAction()
{
$model = new Application_Model_Guestbook();
$request = $this->getRequest();
if ($request->isPost()) {
Print_r('posted');die();
}
$model = Application_Model_GuestbookMapper::find($this->getRequest()->getParam('id'), $model);
$form = new Application_Form_Guestbook(array('model' => $model));
$this->view->form = $form;
}
而且改變了視圖索引提供一個鏈接到編輯動作:
<?php foreach ($this->entries as $entry): ?>
<?php $url = $this->url(
array(
'controller' => 'guestbook',
'action' => 'edit',
'id'=>$entry->id
),
'default',
true)
?>
<dt><?php echo $this->escape($entry->email) ?></dt>
<dd><a href="<?php echo $url; ?>"><?php echo $this->escape($entry->comment) ?></a></dd>
<?php endforeach ?>
映射器是標準 - 直複製和從參考指南粘貼。
當我通過點擊(HTTP://快速啓動/留言/編輯/ ID/1),我面臨着一個異常:[方法 「getDbTable」 不存在,並沒有被困在__call()]
getDbTable()由find()函數調用,該函數位於同一個文件中。爲什麼不能找到getDbTable()?
我運行:PHP版本5.3.3-7 + squeeze1,Zend引擎V2.3.0,阿帕奇/ 2.2.16(Debian的)
,因爲你($ id,Application_Model_Guestbook $留言本) { $ result = $ this-> getDbTable() - > find($ id);這是一個靜態方法,並且找不到靜態方法 – venimus
。 if(0 == count($ result)){ return; } $ row = $ result-> current(); ($ row-> email) - > setComment($ row-> comment) - > setCreated($ row-> created); } – Grokling
對不起,格式太糟糕了!請參閱[link](http://framework.zend.com/manual/en/learning.quickstart.create-model.html)上的代碼以獲取清晰的版本。 我正在關注find()的一個示例調用,這是我在其他地方找到的。我有限的理解表明,只要我傳遞一個Application_Model_Guestbook引用作爲參數,該對象就會受到該方法的影響。 – Grokling