Difference between #4 and #7 of
Creating a Dependent Dropdown From Scratch in Yii2


Title changed

Creating a Dependent Dropdown From Scratch in Yii2

Category unchanged


Yii version unchanged

Tags unchanged

yii2, dependent dropdown

Content changed

I have read http://www.yiiframework.com/wiki/24/creating-a-dependent-dropdown/ (Dependen Dropdown Yii1), but I can't implementation it in Yii2 because Yii2 notdoes not have built-in AJAX functionality hem.. I am searched about it and get this statemencame across this post > qiangxue commented on Aug 28, 2013 In 2.0 we removed most in-page js code. You should write explicit js code in external js files to achieve similar result as in 1.1. The code is very trivial though. So we must create our own code hehe oh no we can use great extension http://demos.krajee.com/widget-details/depdrop, this right but some one dislike use third party too much.. Oke I try to explain You about this classic case :)
### Create Dropdown
First, You should know how to make dropdown in Yii2, I use activefield
public function actionLists($id)

$countPosts = \common\models\Post::find()
->where(['category_id' => $id])

$posts = \common\models\Post::find()
->where(['category_id' => $id])

($countP (!empty($posts>0))) { foreach($posts as $post) { echo "<option value='".$post->id."'>".$post->title."</option>"; } }
 else {
echo "<option>-</option>";

### Any question? or any other idea??
### Reference [membuat dependent dropdown tanpa extension tambahan](http://www.hafidmukhlasin.com/2014/07/02/yii2-membuat-dependen-dropdown-tanpa-extension-tambahan/ "membuat dependent dropdown tanpa extension tambahan")
4 1
Viewed: 126 685 times
Version: 2.0
Category: How-tos
Written by: ThePr0f3550r
Last updated by: alrazi
Created on: Jul 2, 2014
Last updated: 3 years ago
Update Article


View all history