Php ZF条令模型类扩展基类

Php ZF条令模型类扩展基类,php,zend-framework,model,doctrine,Php,Zend Framework,Model,Doctrine,很明显,我已经深陷其中了。我未能理解扩展基础模型的Doctrine ModelClass和Model Table类的好处 比如说 class StaffStaff extends Base_StaffStaff { public function getStaffInformation($id_staff_staff){ // == getInformationsByStaff() $query = Doctrine_Query::create()

很明显,我已经深陷其中了。我未能理解扩展基础模型的Doctrine ModelClass和Model Table类的好处

比如说

class StaffStaff extends Base_StaffStaff
{
    public function getStaffInformation($id_staff_staff){   // == getInformationsByStaff()

        $query = Doctrine_Query::create()
                        ->from("StaffStaff s")
                        ->innerJoin('s.StaffContract c')
                        ->where("s.id_staff_staff = ?", $id_staff_staff);
        $result = $query->execute();

        return $result;

    }
}
在控制器中

StaffController{

    public function readAction() {

        $id = $this->getRequest()->getParam("id_staff_staff");

        // Get information about a staff
        $model = new StaffStaff();
        $q = $model->getStaffInformation($id);

        $this->view->data = $q[0];

/**
*
* Why do you have to say $q[0] ?
* Is there no better way of doing it?
* How can we access the properties from other tables contained inside the BaseClass extended by the ModelClass
*
*/
}
型号:

/**
 * Base_StaffStaff
 * 
 * This class has been auto-generated by the Doctrine ORM Framework
 * 
 * @property integer $id_staff_staff
 * @property integer $fk_id_staff_individual
 * @property integer $fk_id_staff_team
 * @property integer $fk_id_staff_function
 * 
 */

使用查询生成器API时,
getStaffInformation()
函数中的查询是如何组合的,
execute()
方法返回一个iterable游标。这个游标本质上是一个数组,这就是为什么$q[0]将访问第一个元素

如果您尝试只返回一个结果,则应使用
getSingleResult()

$query = Doctrine_Query::create()
   ->from("StaffStaff s")
   ->innerJoin('s.StaffContract c')
   ->where("s.id_staff_staff = ?", $id_staff_staff);
return $query->getSingleResult();
另一方面,iterable光标非常整洁,因为您可以执行以下操作:

$staff = $model->getStaffInformation($id);
foreach($staff as $person)
{
   // Assign all staff to view array
   $this->view->staff[] = $person;
}

使用查询生成器API时,
getStaffInformation()
函数中的查询是如何组合的,
execute()
方法返回一个iterable游标。这个游标本质上是一个数组,这就是为什么$q[0]将访问第一个元素

如果您尝试只返回一个结果,则应使用
getSingleResult()

$query = Doctrine_Query::create()
   ->from("StaffStaff s")
   ->innerJoin('s.StaffContract c')
   ->where("s.id_staff_staff = ?", $id_staff_staff);
return $query->getSingleResult();
另一方面,iterable光标非常整洁,因为您可以执行以下操作:

$staff = $model->getStaffInformation($id);
foreach($staff as $person)
{
   // Assign all staff to view array
   $this->view->staff[] = $person;
}