我有这两个模型:
class Application_Model_List extends Zend_Db_Table_Abstract
{
protected $_name = 'list';
protected $_primary = 'list_id';
protected $_dependentTables = array('Application_Model_Task');
public function getUserLists($user)
{
$select = $this->select()->from($this->_name)->where('list_user = ?',$user);
return $this->fetchAll($select);
}
}
和
class Application_Model_Task extends Zend_Db_Table_Abstract
{
protected $_name = 'task';
protected $_primary = 'task_id';
protected $_referenceMap = array(
'List' => array(
'columns' => 'task_list_id',
'refTableClass' => 'Application_Model_List',
'refColumns' => 'list_id'
)
);
}
我在我的控制器中调用getUserLists
,如下所示:
public function indexAction()
{
$lists = new Application_Model_List();
$userLists = $lists->getUserLists(1);
$this->view->lists = $userLists;
}
并将其传递给我的视图,然后像这样调用findDependentRowset
:
foreach($this->lists as $list){
echo $list->list_title;
$tasks = $list->findDependentRowset('Application_Model_Task');
foreach($tasks as $task){
echo $task->task_title;
}
}
但问题是它从依赖表输出所有行集,而不仅仅是匹配where子句
的行集答案 0 :(得分:0)
糟糕。事实证明这是有效的,但无效的HTML隐藏了我期待的输出