如何避免GII覆盖model内自己新增的算法函数?

请教个问题: 有写算法, 比如 beforesave 之类的, 我 放在 model 里面的

但是 现在 是 敏捷嘛, 数据库 随时都在变. 要刷新 gii 来重新生产 model 的代码.

有什么解决方案么?

1.新生成 myxxxmodel.php

2.算法放在自己的组件里面去, 在控制里面调用.

组件也就是 写成函数 xxxmodelsave($model) { 操作$model里面的东西.完了返回$model

谁有好的建议么?

用giix(到扩展库去找这个extension) 可以避免这一问题 所有跟数据表绑定的东西 在models/_base/BaseXXX.php 中完成

自己的代码 在XXX.php(就是模型文件) 中完成

如果你修改了表结构 那么只需要重新生成BaseXXX 即可

这个问题几乎所以yii程序员都碰到过 :lol:

谢谢 yiqing95.非常完美.

我加改了一些代码.

sql comment to Labels (generateLabelsEx)

public function generateLabelsEx($table, $className) {

    $labels=array();


    $sql ="SELECT COLUMN_NAME, COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '$table->name'";


    $res = Yii::app()->getDb()->createCommand($sql)->query();


    foreach ($res as $column){


            if (!empty($column['COLUMN_COMMENT']))


                    $labels[$column['COLUMN_NAME']]= $column['COLUMN_COMMENT'];


            else


                    $labels[$column['COLUMN_NAME']]= $column['COLUMN_NAME'];





            $labels[$column['COLUMN_NAME']]="Yii::t('app', '".$labels[$column['COLUMN_NAME']]."')";


    }





    // For the relations.


    $relations = $this->getRelationsData($className);


    if (isset($relations)) {


        foreach (array_keys($relations) as $relationName) {


            $labels[$relationName] = null;


        }


    }            


    return $labels;

}