Jaison Justus
Jaison Justus

Reputation: 2793

Yii model overriding

is it possible to override the methods in the yii model. for example i have a model name Books and i need to override all the rules written in the Model. now the Books model have 3 rules defined. what i do is make a new class BooksExt extends the Books model.

class BooksExt extends Books {
 public function rules() {
   return array();
   // i am not using the parent::rules() inside this. 
   // i dont need to use the rules for this model.
 }
 public function search() {
   return 'search override';
   // does this function also get override.
 }
}

does i write a blank rules() method removes all the rules and when i call

$model = new AccountsPrefferredSuppliersExt;
$model->search();

its printing search override. does it accept the rules as empty array. friends can you just check and please responds.

thanks in advance.. have a nice day

Upvotes: 0

Views: 1938

Answers (1)

Oleg
Oleg

Reputation: 7377

Yes, method rules() in BooksExt will return an empty array. Read about Class Hierachies And Overriding.

Upvotes: 1

Related Questions