yii2高级id菜单

yii2高级id菜单,yii2,yii2-advanced-app,Yii2,Yii2 Advanced App,我正在尝试在我的控制器中创建if-else,但不知道如何才能做到这一点。下面是我的控制器和菜单代码 我的要求是关于页面如何显示所有3个要求,但当我尝试时,我只能一个一个地显示,我想这样做,因为我只想在同一页面中按组显示文档,所以这可能吗 那么,else语句是否可以用array检查呢?如果可以,我怎么能检查呢?因为我有一堆必须检查的id 这是我对控制器的看法 public function actionAbout($id = null){ // join with other ta

我正在尝试在我的控制器中创建if-else,但不知道如何才能做到这一点。下面是我的控制器和菜单代码 我的要求是关于页面如何显示所有3个要求,但当我尝试时,我只能一个一个地显示,我想这样做,因为我只想在同一页面中按组显示文档,所以这可能吗

那么,else语句是否可以用array检查呢?如果可以,我怎么能检查呢?因为我有一堆必须检查的id 这是我对控制器的看法

public function actionAbout($id = null){
        // join with other table by province
        if ($id  == '15' )  {
          $query = bio::find()
            ->joinWith('wat')
            ->where(['wat.province' => $id ]);
        }
        // join with other table by amphur
        if ($id  == array('178, 179, 180, 181, 182, 183'))  {
          $query = bio::find()
            ->joinWith('wat')
            ->where(['wat.amphur' => $id ]);
        }else{
        // ///////// like menu list //////////
          $query = Bio::find()
            ->where(['LIKE', 'rolerule', $id]);
        }
        // $query = Bio::find()->orderBy('bio_id DESC')->where(['status' => 1]);
        $countQuery = clone $query;
          $pages = new Pagination(['defaultPageSize' => 30 ,'totalCount' => $countQuery->count()]);
          $models = $query->offset($pages->offset)
            ->limit($pages->limit)
            ->all();

        return $this->render('about', [
          'records' => $models,
          'pages' => $pages,
        ]);
      }
这是我的菜单

<a href="#demo2" class="list-group-item list-group-item-info" data-toggle="collapse" data-parent="#MainMenu">provience</a>
<div class="collapse" id="demo2">
  <a href="about?id=178" class="list-group-item"> provience </a>
</div>
<a href="#demo3" class="list-group-item list-group-item-info" data-toggle="collapse" data-parent="#MainMenu">Amphur</a>
<div class="collapse" id="demo3">
  <a href="about?id=178" class="list-group-item"> Amphur </a>
  <a href="about?id=179" class="list-group-item"> muang</a>
  <a href="about?id=180" class="list-group-item"> test1</a>
  <a href="about?id=181" class="list-group-item"> test2</a>
  <a href="about?id=182" class="list-group-item"> test3</a>
  <a href="about?id=183" class="list-group-item"> test4</a>
</div>
<a href="#demo4" class="list-group-item list-group-item-info" data-toggle="collapse" data-parent="#MainMenu">hero</a>
<div class="collapse" id="demo4">
  <a href="about?id=hero" class="list-group-item">hero</a>
  <a href="about?id=superman" class="list-group-item">superman</a>
  <a href="about?id=batman" class="list-group-item">batman</a>
  <a href="about?id=ironman" class="list-group-item">ironman</a>
</div>

您只得到最后一个查询,因为您当时重新分配了它

假设您可以测试$your\u test\u var与您的值,这可能是一个建议

public function actionAbout($id = null){
        // join with other table by province
        if ($your_test_var == 'your_first_val' )  {
          $query = bio::find()
            ->joinWith('wat')
            ->where(['wat.province' => $id ]);

        }
      // join with other table by amphur
        if ($your_test_var == 'your_second_val' )  {
         $query = bio::find()
           ->joinWith('wat')
           ->where(['wat.amphur' => $id ]);
        } else {
      // ///////// like menu list //////////
      $query = Bio::find()
        ->where(['LIKE', 'rolerule', $id]);
      }
    // $query = Bio::find()->orderBy('bio_id DESC')->where(['status' => 1]);
     $countQuery = clone $query;
     $pages = new Pagination(['defaultPageSize' => 30 ,'totalCount' => $countQuery->count()]);
     $models = $query->offset($pages->offset)
         ->limit($pages->limit)
         ->all();

     return $this->render('about', [
          'records' => $models,
          'pages' => $pages,
     ]);
 }

它可以工作,但我如何在第二个语句中发送我的值我有一堆id,那么我如何检查它?`//通过ampher if($id='178179180181182183184185186187188'){$query=bio::find()->joinWith('wat')->where(['wat.ampher'=>$id]);else与其他表连接{`Please..update your question with the property code and explain your question..in comment不可能在Tsand code.下面是您现在要找的..我的意思是可以检查数组中的if条件吗?您可以在if条件下检查数组的值..例如:if($array[3]='my_value'))…否则请解释清楚。你的问题。