0
votes

I'm looking at some code I have inherited. In all the Model classes - any method that does a "Select" query has been declared as static where as the "insert", "update", "delete" are not declared as static in the same Model class.

For example

require_once 'Zend/Db/Table/Abstract.php';

class Model_Course extends Zend_Db_Table_Abstract {

protected $_name = 'course';
public static function getCoursesByFaculty($faculty_id)
{
   $courseModel = new self();
   $select = $courseModel->select();
   $select->setIntegrityCheck(false);
   $select->from('course', 'course.*');
   $select->joinLeft('course_faculty', 'course.course_id = course_faculty.course_id');
   $select->order(array('title'));
   $select->where('faculty_id = '.$faculty_id);
   return $courseModel->fetchAll($select);
}
}

Is there any good reason/advantages for declaring these methods as static ?

Thanks for your input

1

1 Answers

0
votes

I dont think any advantages rather than calling it easily like Modelclass::function() By the way i found out some ways to tweaks your code

require_once 'Zend/Db/Table/Abstract.php'; /*Actually this require is not required if you configure your includePaths correctly*/

class Model_Course extends Zend_Db_Table_Abstract {

protected $_name = 'course';
public static function getCoursesByFaculty($faculty_id)
{

   $select = $this->select();
   $select->setIntegrityCheck(false);
   $select->from($this, 'course.*');
          ->joinLeft('course_faculty', 'course.course_id = course_faculty.course_id');
          ->order(array('title'));
          ->where('faculty_id = ?',$faculty_id);
   $rows = $this->fetchAll($select);
return (!empty($rows)) ? $rows : null;

}