DetailView::widget 和 GridView::widget 判断 [ 2.0 版本 ]
GridView::widget
--->各种判断
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute'=>'stu_sex',
'value'=>function($dataProvider){
return $dataProvider->stu_sex==1?"男":"女";
}
],
]
]); ?>
DetailView::widget
判断性别
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model backend\models\Student */
$this->title = $model->stu_id;
$this->params['breadcrumbs'][] = ['label' => 'Students', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
//这里是判断性别的,也可以用 switch 来判断
$model->stu_sex==0?($model->stu_sex="女"):($model->stu_sex="男");
//联系人关系
switch($model->stu_person_real){
case "1";echo $model->stu_person_real="父";break;
case "2";echo $model->stu_person_real="母";break;
case "3";echo $model->stu_person_real="其他";break;
}
?>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'stu_sex',
],
]) ?>
怜晚情之泪 上海
注册时间:2016-11-29
最后登录:2020-11-05
在线时长:27小时29分
最后登录:2020-11-05
在线时长:27小时29分
- 粉丝4
- 金钱880
- 威望130
- 积分2450
共 0 条评论