您好,我需要帮助显示来自2个表的数据。如何在Zend Framework中显示来自2个相关表的数据
,所以我有2种型号:
//Klasy.php
class Model_Klasy extends Zend_Db_Table_Abstract
{
protected $_name = 'klasy';
protected $_primary = 'id';
protected $_referenceMap = array(
'Nauczyciele' => array(
'columns' => array('Wychowawca'),
'refTableClass' => 'Model_Nauczyciele',
'refColumns' => array('id')
)
);
public function listaKlas()
{
$dane = $this->select();
return $this->fetchAll();
}
}
和
//Nauczyciele.php
class Model_Nauczyciele extends Zend_Db_Table_Abstract
{
protected $_name = 'nauczyciele';
protected $_dependentTables = 'Model_Klasy';
}
在控制器具有代码:
public function listaAction()
{
$modelLista = new Model_Klasy();
$this->view->listaKlas = $modelLista->listaKlas();
}
,并查看此:
<b>Lista Klas:</b>
<table>
<tr>
<th>Klasa</th>
<th>Rok rozpoczęcia nauki</th>
<th>Wychowawca</th>
</tr>
<tr><?php echo $this->partialLoop('partials/ListaKlas.phtml', $this->listaKlas); ?></tr>
</table>
个
和部分文件ListaKlas.phtml:
<tr>
<td><?php echo $this->nazwa; ?></td>
<td><?php echo $this->rok_rozpoczecia; ?></td>
<td>
<?php
echo $this->Wychowawca;
?>
</td>
<td style="width: 5%">
<a href="<?php echo $this->baseUrl() . '/klasy/edytuj/id/';
echo $this->id ;?>">Edytuj
</a>
</td>
<td style="width: 5%">
<a href="<?php echo $this->baseUrl() . '/klasy/usun/id/';
echo $this->id ;?>">Usuń
</a>
</td>
</tr>
从表Nauczyciele我想显示2列,但不知道怎么办。我知道方法findParentRow但不知道在哪里使用它,以及如何渲染来自第二个表的数据。在我的情况下,我只看到Klasy表中的ID。
感谢您的信息。我现在必须读更多关于这个。在我学习ZF的书中,我写的就像在我的例子中。我必须改变它。 – WooCaSh 2010-10-24 14:03:05
我把我的模型改成这个方法,告诉我什么。感谢帮助 – WooCaSh 2010-10-26 14:27:13