示例#1
0
?>
</h3>
    
        <p class="action">
            <?php 
echo Html::a('添加管理员', ['create'], ['class' => 'btn btn-success']);
?>
        </p>
    </div>

    <?php 
Pjax::begin();
?>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['attribute' => 'id', 'options' => []], ['attribute' => 'username', 'label' => '管理员账号'], ['attribute' => 'role_id', 'label' => '角色', 'value' => function ($model) {
    return Role::findOne($model->role_id)->role_name;
}], ['attribute' => 'created_at', 'label' => '创建时间', 'value' => function ($model) {
    return date('Y-m-d H:i', $model->created_at);
}], ['header' => Html::a('状态', 'javascript:;'), 'content' => function ($model) {
    if ($model->status == 1) {
        return Html::img('@web/image/yes.gif', ['onclick' => "setStatus(this, {$model->id})", 'data-status' => 0]);
    } else {
        return Html::img('@web/image/no.gif', ['onclick' => "setStatus(this, {$model->id})", 'data-status' => 1]);
    }
}], ['class' => 'yii\\grid\\ActionColumn', 'header' => Html::a('操作', 'javascript:void(0);'), 'template' => '{update} {delete}']]]);
?>
    <?php 
Pjax::end();
?>

</div>
示例#2
0
 /**
  * Finds the Role model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Role the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Role::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }