当前位置:Gxlcms > PHP教程 > yii2模板twig中使用GridView::widget

yii2模板twig中使用GridView::widget

时间:2021-07-01 10:21:17 帮助过:21人阅读

这篇文章主要介绍了关于yii2 模板twig中使用GridView::widget ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

yii框架twig模板中使用GridView::widget 需要这样写:

  1. {{ grid_view_widget({
  2. 'dataProvider': provider,
  3. 'columns': [
  4. 'id',
  5. {'attribute' : 'create_user_id', 'label' : '用户ID'},
  6. {'attribute' : 'category_id','value':ticketCategory, 'label' : '问题分类'},
  7. {'attribute' : 'language', 'value':languageAction, 'label' : '语言'}, //languageAction为需要单独处理的数据,模板不支持PHP语法,需要从控制器返回
  8. {'attribute' : 'support_user_id','value':supportUser, 'label' : '受理人'},
  9. {
  10. 'attribute': 'create_time',
  11. 'format':['datetime', 'yyyy-MM-dd HH:mm:ss'],
  12. 'label': ' 创建时间',
  13. },
  14. {
  15. 'attribute': 'update_time',
  16. 'format':['datetime', 'yyyy-MM-dd HH:mm:ss'],
  17. 'label': ' 更新时间',
  18. },
  19. {
  20. 'attribute': 'response_time',
  21. 'value':responseTime,
  22. 'label': ' 响应时间(分)',
  23. },
  24. {'label':'操作', 'value':actionFunction, 'format':'raw'},
  25. ]
  26. }) }} 

  模板里面不支付PHP写法,比如language字段value值数据库存入标识,而前台页面需要显示对应表示的内容,可以在控制器层将数据处理好,以变量的方式发送到前端页面:

  1. $languageAction = function ($model)
  2. {
  3. switch ($model->language)
  4. {
  5. case Ticket::LANGUAGE_ZH :
  6. return $model->language = '中文';
  7. case Ticket::LANGUAGE_EN :
  8. return $model->language = '英文';
  9. case Ticket::LANGUAGE_OTHER :
  10. return $model->language = '其他';
  11. }
  12. };
  13. return $this->controller->render('index',['provider' => $data,'languageAction' => $languageAction]);

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

Laravel 修改默认日志文件名称和位置

PHP使用Azure Storage Blob上传文件

以上就是yii2 模板twig中使用GridView::widget的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行