Revision #6 has been created by alrazi on Nov 21, 2017, 2:39:53 PM with the memo:
remove redundant queries
« previous (#5) next (#7) »
Changes
Title
unchanged
Creating a Dependent Dropdown From Scratch in Yii2
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
yii2, dependent dropdown
Content
changed
[...]
```php
public function actionLists($id)
{
$countPosts = \common\models\Post::find()
->where(['category_id' => $id])
->count();
$posts = \common\models\Post::find()
->where(['category_id' => $id])[...]
->all();
if($countP (!empty($posts
>0))) {
foreach($posts as $post)
{
echo "<option value='".$post->id."'>".$post->title."</option>";
}
}
else{
echo "<option>-</option>";
}
}
```[...]