私はzendを初めて使用します。かつてプレーンPHPで作成されていたWebサイトを再開発し、それをzendフレームワークに組み込むように依頼されました。
私はデータベースの関係に多くの問題を抱えています。関係の定義とクエリに頭を悩ませているようには見えません。
カテゴリを探したいのですが。そのカテゴリから、それに関連付けられているすべての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');
}
}
まず...私は何か間違ったことをしていますか?
次に...依存する行セットをクエリするにはどうすればよいですか?