Yii项目知识搜集

[['rId','advertiser_id','image_file'], 'unique','targetAttribute'=>['rId','advertiser_id','image_file'],'message'=>'重复插入数据'],//设置多个字段唯一

  

public static function getTableSchema()  //设置字段的可变属性
{
        $schema = parent::getTableSchema();
        $schema->columns['age']->phpType = 'string';
        return $schema;
}

  

 public function behaviors()
    {
        return !empty($this->getDirtyAttributes())?[ //设置脏字段时最后更新时间变动
            'timestamp' => [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_time', 'last_modified_time'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => 'last_modified_time',
                ],
                'value' => function() { return date('Y-m-d H:i:s'); },
            ],
        ]:(parent::behaviors());
    }    

  

posted @ 2017-06-07 11:28  雨落知音  阅读(110)  评论(0编辑  收藏  举报