Home >Backend Development >PHP Tutorial >Using GridView::widget in yii2 template twig
This article mainly introduces the use of GridView::widget in yii2 template twig, which has certain reference value. Now I share it with you. Friends in need can refer to it.
Used in yii framework twig template GridView::widget needs to be written like this:
{{ 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'}, ] }) }}
There is no PHP writing method in the template. For example, the language field value value database stores the logo, and the front page needs to display the corresponding content. You can The controller layer processes the data and sends it to the front-end page in the form of variables:
$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]);
The above is the entire content of this article, I hope it will be useful for everyone’s learning Help, please pay attention to the PHP Chinese website for more related content!
Related recommendations:
Laravel Modify the default log file name and location
PHP uses Azure Storage Blob to upload files
The above is the detailed content of Using GridView::widget in yii2 template twig. For more information, please follow other related articles on the PHP Chinese website!