Reputation: 65
i am trying to create if else in my controller but have no idea how can id do that here is my Controller and menu code given bellow there my requirement is in about page how can i show that all 3 quires but when i try i can show only one by one i want to do that because i just wanna show documents by group in same page so is that possible ?
here is my about Controller
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,
]);
}
here is my about menu
<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>
Upvotes: 2
Views: 61
Reputation: 133400
You get only the last query because you reassign it then
Assuming you can test $your_test_var against you_value this coulb be a suggestion
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,
]);
}
Upvotes: 1