怜晚情之泪 2016-12-07 16:53:14 5532次浏览 0条评论 1 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',
    ],
]) ?>

panduan.png

觉得很赞
    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册