开发者

Zend Framework: How to write a correct model that use another table?

开发者 https://www.devze.com 2023-02-27 19:13 出处:网络
I have models in project that use more than one table to select. How can I write code like this more correct?

I have models in project that use more than one table to select.

How can I write code like this more correct?

public function __c开发者_如何学Pythononstruct() {

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

}

public function init() {

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

}

public function 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;

}


$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");
0

精彩评论

暂无评论...
验证码 换一张
取 消