Yii2 不使用 gridview 没有结果消息

Yii2 no result message without using gridview

我的控制器:

 public function actionResults()
{

     $query = User::find();

     $admins = $query->orderBy('id')->andWhere('role_id = 1')->all();

     $searchModel = new AdminSearch();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

    return $this->render('results', [
        'admins' => $admins,
        'dataProvider' => $dataProvider,
        'searchModel' => $searchModel,
    ]);
}

查看结果:

<table class="table">
<thead>
<tr>
    <th>ID</th>
    <th>Name</th>
    <th>Create Date</th>
</thead>
<tbody>
<?php foreach  ($dataProvider->models as $model){ ?>
<tr>
    <td><?= $model->username; ?></td>

    <td><?=$model->fullname; ?></td>

    <td><?=$model->email; ?></td>
    </tr>

我不想使用 Gridview 来呈现结果,但不知道如何抛出无结果消息。

请帮帮我

谢谢

Se php isset() 和 empty() 函数检查数组中是否有数据

  if(isset($dataProvider->models) && !empty($dataProvider->models)){
        //do you foreach loop here
    }else {
        echo 'empty';
    }