Php Zend框架fetchall函数
在我的组织模式中,我有以下功能Php Zend框架fetchall函数,php,zend-framework,Php,Zend Framework,在我的组织模式中,我有以下功能 public function getOrganisations($where=null,$order='name ASC',$offset=null,$limit=null){ $Result = $this->fetchAll($where,$order,$limit,$offset); if (!$Result){ return array(); }
public function getOrganisations($where=null,$order='name ASC',$offset=null,$limit=null){
$Result = $this->fetchAll($where,$order,$limit,$offset);
if (!$Result){
return array();
}
return $Result->toArray();
}
但是我如何才能包括我的组织类型模型,以便我可以在组织表中左键连接到组织类型id?也许使用
Zend\u Db\u Select
和joinLeft()
更合适:
这是支持使用数据映射器模式的论点的核心。
使用您在示例中使用的结构,尝试将
组织类型
对象传递到组织
模型时会遇到很大的困难。但是,您可以在查询中执行联接,以联接到组织类型
表,但联接对象可能不合理
致:
这将使您了解表联接的工作方式。如果要使用这些对象,则需要从不同的结构重新开始我在PHPMaster上找到了一些不错的教程,帮助我了解了数据映射器和域模型。
此外,在线书籍还提供了数据映射器模式以及如何测试它的一个很好的示例。
祝你好运
//assuming this is a DbTable model that extends Zend_Db_Table_Abstract
function getOrganisations($where=null,$order='name ASC',$offset=null,$limit=null){
$select = $this->select()->setIntegrityCheck(FALSE);//This locks the table to allow joins
$select->joinLeft('organisation_types', 'organisation_types.id = organisation.organisation_type_id');//This will join the tables with all feilds, use the join type you like.
if (!is_null($where) {
$select->where($where);
}
if (!is_null($order) {
$select->order($order);
}
if (!is_null($offset) {
$select->limit(null,$offset);//offset is second arg in limit() in select()
}
if (!is_null($limit) {
$select->limit($limit);
}
$Result = $this->fetchAll($select);
if (!$Result){
return array();
}
return $Result->toArray();
}