0

継承したコードを見ています。すべての Model クラスで、"Select" クエリを実行するメソッドはすべて static として宣言されていますが、"insert"、"update"、"delete" は同じ Model クラスで static として宣言されていません。

例えば

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

class Model_Course extends Zend_Db_Table_Abstract {

保護された $_name = 'コース';
public static function getCoursesByFaculty($faculty_id)
{
   $courseModel = 新しい自己();
   $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);
   $courseModel->fetchAll($select); を返します。
}
}

これらのメソッドを static として宣言する正当な理由/利点はありますか?

ご意見ありがとうございます

4

1 に答える 1

0

Modelclass :: function()のように簡単に呼び出すのではなく、利点はないと思います。ところで、コードを微調整する方法をいくつか見つけました。

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;

}
于 2012-05-16T10:21:34.797 に答える