0
在zend框架2中,我想從兩個表中檢索列名和結果。zf2 Zend Framework 2 paginator從多個表中選擇列
在SQL我可以寫
Select user.name, course.mark from course JOIN user.id=course.user_id;
這將返回我的用戶名,他們的標記
但在ZF2當我想用使用Zend的\ DB \ SQL \得到這樣的結果選擇;不會工作。自從使用分頁以來,我正在使用Zend \ Db \ Sql \ Select。
zf2 User Model
public function fetchAll($pagination = FALSE)
{
if($pagination)
{
// create a new Select object for the table album
$sql = new Sql($this->tableGateway->getAdapter());
$select = $sql->select();
$select->from('course');
$select->join('user', 'user.id = course.user_id',
array('user.name','course.mark')
);
// create a new result set based on the Album entity
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Course());
// create a new pagination adapter object
$paginatorAdapter = new DbSelect(
// our configured select object
$select,
// the adapter to run it against
$this->tableGateway->getAdapter(),
// the result set to hydrate
$resultSetPrototype
);
$paginator = new Paginator($paginatorAdapter);
return $paginator;
}
$resultSet = $this->tableGateway->select();
return $resultSet;
}
我還應該創建一個用戶模型嗎?目前,我只有CourseTable