Hi Guys,
I’ve been using Yii for a bit and have recently begun thinking that it might be best to set in stone the order in which I put functions into my classes, particularly my models, to make everything easier to find. I contemplated Alphabetical ordering, but you really want related functions to be beside eachother, such-as getters and setters, beforeSave and afterSave, and so on. Right now the rough order in which I put them in is:
Class Table Extends CActiveRecord {
/* Static Properties */
/* Properties */
/* Getters/Setters */
public static function model() {}
public function tableName() {}
public function rules() {}
public function relations() {}
/* Transformations/Logic */
public function attributeLabels() {}
public function behaviors() {}
public function search() {}
public function scopes() {}
/* Alternate search functions */
}
Now, this is OK, it’s mostly based on the order that the stock code generation does things, but there are some things I don’t like. You really want the rules to be near what they apply to (The getters/setters and instance properties), and for the relations (which are accessed as properties) to also be near the properties. Of course, standard practice says that the properties be defined before functions at the top of the class. The tableName and model methods will generally remain fixed until the end of time, so putting them at the end might get them out of the way. This gives us:
Class Table Extends CActiveRecord {
/* Static Properties */
/* Properties */
/* Getters/Setters */
public function rules() {}
public function relations() {}
public function attributeLabels() {}
public function behaviors() {}
/* Transformations/Logic */
public function search() {}
public function scopes() {}
/* Alternate search/find functions */
public function tableName() {}
public static function model() {}
}
Does that seem logical? Do any of you have similar schemes you’d be willing to share?