谁一开始就是大神?

GridView中的ActionColumn的template可以根据状态显示不同[2.0]

2016-09-09 18:21:14屏幕截图.png

最终想实现上图效果。
根据状态的不同,可选的操作不同。
我写的逻辑如下图,但是总报错。说是object 转化string 有问题,但是这样写的template的类型是 string

'template' => function ($model) {
                    $temp = [
                        '0' => '{view:view} {update:update} {delete:delete} {show:show}',
                        '1' => '{view:view} {update:update} {delete:delete} {hide:hide}',
                        '2' => '{view:view} {delete:delete}'
                    ];
                    return $temp[$model->state];
                },

我在接口上看template的定义

The template used for composing each cell in the action column. Tokens enclosed within curly brackets are treated as controller action IDs (also called button names in the context of action column). They will be replaced by the corresponding button rendering callbacks specified in $buttons. For example, the token {view} will be replaced by the result of the callback buttons[‘view’]. If a callback cannot be found, the token will be replaced with an empty string.

As an example, to only have the view, and update button you can add the ActionColumn to your GridView columns as follows:

写的问题在那哪里呢,还是不可以实现的啊

你这明显不对嘛。他的api里面写着$template是string类型。你乱来。要这么写:
$template = ‘{preview}{update}{up}{down}{delete}’,就是把你所有可能出现的操作写进去,然后设置ActionColumn的buttons属性:
‘buttons’ => [
‘preview’ => function($url, $model, $key) {
},
…其他button
];
要在buttons里面判断是否显示这个链接。

赞(0) 打赏
未经允许不得转载:菜鸟之家 » GridView中的ActionColumn的template可以根据状态显示不同[2.0]

评论 抢沙发

登录

找回密码

注册