我使用Zend 2 Framework構建我的web應用程序。我通過本教程實現了我的數據庫表模型:http://framework.zend.com/manual/2.1/en/user-guide/database-and-models.htmlZend 2 Framework中的多對多關係
我在數據庫中的兩個模型之間有多對多的關係。從他們那裏獲取數據我搜索了一下,發現這個鏈接:http://mattmccormick.ca/2010/04/24/how-to-easily-create-models-and-table-relationships-in-zend-framework/
問題是所有的表模型從Zend_Db_Table_Abstract
延伸的例子。我不知道如何從模型中獲取數據。
我有一個包含投票的表格,每個投票都有一個唯一的哈希ID。每個投票也都有標籤。因此,我定義了一個表格tags
,其中包含所有可用標籤和一個voting_tag_map
,其中映射了所有多對多關係。
我至今嘗試過如下,這是代碼從我VotingTable
類:
public function getTagsByVoting($votingHash){
$select = $this->tableGateway->getSql()->select();
$select->from(array('v' => 'voting'))
->join('voting_tag_map', 'v.voting_id=voting_tag_map.voting_id')
->join('tags', 'voting_tag_map.tag_id=tags.tag_id');
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
}
它接着說:因爲從()方法的
Since this object was created with a table and/or schema in the constructor, it is read only.
那。如果我刪除from()方法,它說:
Statement could not be executed
任何人都可以幫助我嗎?