Jump to content
Larry Ullman's Book Forums

Gii/giix Model And Crud


ewbarnard
 Share

Recommended Posts

Larry,

 

Concerning Chapter 4, Generating Code with Gii (p. 69ff):

 

In the tip at the end of the chapter (p. 76), you mention ways to customize Gii. This would be a great place to mention the Giix extension which you do describe later in your book.

 

I use giix exclusively, and am extremely pleased. I find that I'm often tweaking table schema during development, and giix allows me to regenerate the base model without touching the model code that I write.

 

Another item worth mentioning with respect to Giix: Here are a couple of low-impact ways to override the base model functions.

 

Example 1. To add to the base rules, without copying the entire set of rules:

 

    public function rules() {        $rules = parent::rules();        $rules[] = array('filename', 'file',                          'allowEmpty' => false,                          'types' => 'csv',                         'wrongType' => 'The load file must be .csv',                         );        return $rules;    }

With the above, you can regenerate the base model class with giix, and not have to re-edit your rules() method.

 

Example 2. Tweak one of the attribute labels. Again, this allows you to tweak a single label without copying the entire attributeLabels() method, and therefore not having to edit anything if you re-generate the base model class:

 

    public function attributeLabels() {        $labels = parent::attributeLabels();        $labels['filename'] = Yii::t('app', 'Load File');        return $labels;    }

 

Link to comment
Share on other sites

  • 2 weeks later...
 Share

×
×
  • Create New...