【问题标题】:Yii2 : Setting two values of Key in SqlDataProviderYii2 : 在 SqlDataProvider 中设置 Key 的两个值
【发布时间】:2015-07-05 14:45:06
【问题描述】:

我在数据库中有一个表Have_Schedule(多对多关系),其中包含来自表的外键:

学生:student_id,student_name

时间表:sch_id、sch_day、sch_time

Have_Schedule : student_id, sch_id

我想像这样使用SqlDataProvider 创建DataProvider

$dataProvider = new SqlDataProvider([
            'sql' => $sql,
            'totalCount' => $n,
            'key' => '', // <--------- the key
            'sort' => [
                'attributes' => [
                    'student_name',
                    'sch_day',
                    'sch_time',
                ],
            ],
            'pagination' => [
                'pageSize' => 20,
            ],
        ]);

密钥将用于ActionColumn,例如:/view?student_id=1&amp;sch_id=2

如何使用student_idsch_id 设置键值?

【问题讨论】:

    标签: key yii2 dataprovider


    【解决方案1】:

    最简单的方法不是创建/使用 ActionColumn,而是您可以使用 raw-column 并在那里显示您想要的内容:

    [
       'attribute' => 'some_title',
       'format' => 'raw',
       'value' => function ($model) {                      
           return '<a href="'.$yourUrl .'">your Text</a>';
       },
    ],
    

    【讨论】:

    • @Bhuvanesh 请使用您正在使用的代码发布一个新的正确问题,并更好地解释您需要什么,并最终将新问题的链接评论给我
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    相关资源
    最近更新 更多