2016-09-09 18:27:08 2981次浏览 1条回答 0 悬赏 10 金钱

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:

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

最佳答案

  • morose 发布于 2016-09-12 15:55 举报

    你这明显不对嘛。他的api里面写着$template是string类型。你乱来。要这么写:

    $template = '{preview}{update}{up}{down}{delete}',就是把你所有可能出现的操作写进去,然后设置ActionColumn的buttons属性:

    'buttons' => [
    'preview' => function($url, $model, $key) {

     if (判断) {return Html::a('返回一个链接');
    

    },
    ...其他button
    ];

    要在buttons里面判断是否显示这个链接。

    1 条回复
    回复于 2016-09-12 16:32 回复

    我返回的数组的值不是string吗??

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
37370
等待激活

37370

注册时间:2016-10-31
最后登录:1970-01-01
在线时长:0小时0分
  • 粉丝1
  • 金钱45
  • 威望0
  • 积分45

热门问题