1

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

我怎样才能更正确地编写这样的代码?

公共函数 __construct() {

   $this->_name = DB_PREFIX . 'teachers';
   parent::__construct();

}

公共函数初始化(){

  $this->db = Zend_Db_Table::getDefaultAdapter();

}

公共函数 getTeachers($course_id) {

  $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;

}

4

1 回答 1

0
$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");
于 2011-04-22T12:16:58.937 回答