我是zend的新手。我被要求重新開發曾經用普通PHP編寫的網站,並將其放入zend框架中。zend與select的關係
我在數據庫關係方面遇到了很多麻煩,我似乎無法讓我的腦袋定義和查詢關係。
我想找到一個類別。從那個類別中,我希望能夠找到與它關聯的所有CategoryInfo,並且能夠查詢/排序/限制該數據集。
這是我的模特。
Categorys.php
<?php
class Default_Model_Categorys extends Zend_Db_Table_Abstract
{
protected $_name = 'Categorys';
protected $_primary = 'id';
protected $_dependentTables = array('Default_Model_CategoryInfo');
}
?>
CategoryInfo.php
<?php
class Default_Model_CategoryInfo extends Zend_Db_Table_Abstract
{
protected $_name = 'Category_Info';
protected $_primary = 'id';
protected $_referenceMap = array(
'Categorys' => array(
'columns' => array('cat_id'),
'refTableClass' => 'Default_Model_Categorys',
'refColumns' => array('id')
)
);
}
?>
CategoryController.php
<?php
class CategorysController extends Zend_Controller_Action
{
public function indexAction()
{
/*
this should redirect to all games
*/
return $this->_forward("index", "games");
}
public function categoryAction()
{
/*
shows a specific category
*/
$id = (int) $this->_request->getParam('id');
$category = new Default_Model_Categorys();
$this->view->category = $category->fetchRow(
$category->select()->where('id = ?', $id)
);
$categoryInfo = $this->view->category->findDependentRowset('Default_Model_CategoryInfo');
}
}
首先......我我做錯了什麼?
其次......我該如何去查詢依賴行集?
比爾你英雄。我謝謝你!問題解決了。 – sfusion 2009-09-22 08:27:29
很高興幫助!我編輯了上面的代碼,將調用添加到'current()',因爲'find()'總是返回一個行集合,而不是一行。 – 2009-09-22 08:35:24