时间:2021-07-01 10:21:17 帮助过:21人阅读
yii框架twig模板中使用GridView::widget 需要这样写:
- {{ grid_view_widget({
- 'dataProvider': provider,
- 'columns': [
- 'id',
- {'attribute' : 'create_user_id', 'label' : '用户ID'},
- {'attribute' : 'category_id','value':ticketCategory, 'label' : '问题分类'},
- {'attribute' : 'language', 'value':languageAction, 'label' : '语言'}, //languageAction为需要单独处理的数据,模板不支持PHP语法,需要从控制器返回
- {'attribute' : 'support_user_id','value':supportUser, 'label' : '受理人'},
- {
- 'attribute': 'create_time',
- 'format':['datetime', 'yyyy-MM-dd HH:mm:ss'],
- 'label': ' 创建时间',
- },
- {
- 'attribute': 'update_time',
- 'format':['datetime', 'yyyy-MM-dd HH:mm:ss'],
- 'label': ' 更新时间',
- },
- {
- 'attribute': 'response_time',
- 'value':responseTime,
- 'label': ' 响应时间(分)',
- },
- {'label':'操作', 'value':actionFunction, 'format':'raw'},
- ]
- }) }}
模板里面不支付PHP写法,比如language字段value值数据库存入标识,而前台页面需要显示对应表示的内容,可以在控制器层将数据处理好,以变量的方式发送到前端页面:
- $languageAction = function ($model)
- {
- switch ($model->language)
- {
- case Ticket::LANGUAGE_ZH :
- return $model->language = '中文';
- case Ticket::LANGUAGE_EN :
- return $model->language = '英文';
- case Ticket::LANGUAGE_OTHER :
- return $model->language = '其他';
- }
- };
- return $this->controller->render('index',['provider' => $data,'languageAction' => $languageAction]);
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
Laravel 修改默认日志文件名称和位置
PHP使用Azure Storage Blob上传文件
以上就是yii2 模板twig中使用GridView::widget的详细内容,更多请关注Gxl网其它相关文章!