Zend framework Zend框架:如何编写使用另一个表的正确模型?

Zend framework Zend框架:如何编写使用另一个表的正确模型?,zend-framework,model,zend-framework-mvc,Zend Framework,Model,Zend Framework Mvc,我在项目中有使用多个表来选择的模型 我怎样才能写出这样更正确的代码 公共函数构造 { } 公共函数初始化 { } 公共函数getTeachers$course\u id { } 好的,但是如何得到这个呢?我认为把它写成字符串不是很好。当我试图从模型中获取它时,它失败了。设置一个类属性?私有$secondTable=foo;就为了让你知道$result=$this->db->fetchAll$students\u查询$此->数据库->获取所有$students\u查询:空;可以写为return$t

我在项目中有使用多个表来选择的模型

我怎样才能写出这样更正确的代码

公共函数构造 {

}

公共函数初始化 {

}

公共函数getTeachers$course\u id {

}


好的,但是如何得到这个呢?我认为把它写成字符串不是很好。当我试图从模型中获取它时,它失败了。设置一个类属性?私有$secondTable=foo;就为了让你知道$result=$this->db->fetchAll$students\u查询$此->数据库->获取所有$students\u查询:空;可以写为return$this->db->fetchAll$students\u query;不执行两次查询。如果未返回任何记录,fetchAll将返回null。谢谢,您的建议使其更加完美:
   $this->_name = DB_PREFIX . 'teachers';
   parent::__construct();
  $this->db = Zend_Db_Table::getDefaultAdapter();
  $students_query = $this ->db->select()
                          ->from($this->_name, '')
                          ->from(<ANOTHER_TABLE_NAME>, array('uid', 'ulogin'))
                          ->where("<ANOTHER_TABLE_NAME>.uid = {$this->_name}.teacher_id")
                          ->where("{$this->_name}.course_id = ?", $course_id)
                           ->order("<ANOTHER_TABLE_NAME>.ulogin");

  $result = $this->db->fetchAll($students_query) ? $this->db->fetchAll($students_query) : NULL;

  return $result;
$students_query =  $this->db->select()
                          ->from($this->_name, '')
                          ->setIntegrityCheck(false)
                          ->join('<ANOTHER_TABLE_NAME>', "<ANOTHER_TABLE_NAME>.uid = {$this->_name}.teacher_id", array('uid', 'ulogin'))
                          ->where("{$this->_name}.course_id = ?", $course_id)
                          ->order("<ANOTHER_TABLE_NAME>.ulogin");