Yii 2 migration 给表添加字段

1

php yii migrate/create add_column_rsync_sh_to_conf_table

 2Project 表添加字段 rsync_sh,

class m160730_064717_add_column_rsync_sh_to_conf_table extends Migration
{
    public function up()
    {
        $this->addColumn('project', 'rsync_sh', Schema::TYPE_STRING . '(200) DEFAULT "" COMMENT "执行sh脚本名称"');
    }
 
    public function down()
    {
        echo 'add column rsync_sh success!';
        return false;
    }
}

3

php yii migrate

 

posted on 2017-01-28 13:37 木子炜培先生 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/liadmin/p/6354233.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要给Yii2-GridView中的自定义字段增加排序功能,可以通过以下步骤实现: 1. 在GridView的columns属性中,为自定义字段添加‘attribute’属性(指定排序用的字段),‘label’属性(指定在表头显示的名称),以及‘value’属性(指定自定义字段的值)。 2. 在GridView的dataProvider属性中,为排序用的字段添加一个Sort属性。 3. 在GridView中的排序链接中,为自定义字段添加一个sort参数,指定排序用的字段。 以下是一个示例代码: ``` use yii\grid\GridView; use yii\data\ActiveDataProvider; use yii\data\Sort; $dataProvider = new ActiveDataProvider([ 'query' => $query, 'sort' => [ 'attributes' => [ 'custom_field' => [ 'asc' => ['custom_field' => SORT_ASC], 'desc' => ['custom_field' => SORT_DESC], 'label' => 'Custom Field', ], ], ], ]); echo GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ 'id', 'name', [ 'attribute' => 'custom_field', 'label' => 'Custom Field', 'value' => function ($model) { return $model->customField; } ], ], 'sorter' => [ 'attributes' => [ 'custom_field' => [ 'asc' => ['custom_field' => SORT_ASC], 'desc' => ['custom_field' => SORT_DESC], ], ], ], ]); ``` 在以上代码中,我们为自定义字段‘custom_field’添加一个Sort属性,然后在GridView中为该字段添加了‘attribute’、‘label’和‘value’属性。最后,在排序链接中为自定义字段添加了‘sort’参数,指定排序用的字段。这样就可以为Yii2-GridView中的自定义字段增加排序功能了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值