Yii Dependent Drop Down

how to enhance this code with dependent dropdown??

<div class="row">

	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'subject'); ?&gt;


	&#60;&#33;--&lt;?php echo &#036;form-&gt;textField(&#036;model,'subject',array('size'=&gt;25,'maxlength'=&gt;25)); ?&gt;--&#62;


	&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'subject', CHtml::listData(masterSubject::model()-&gt;findAll(), &quot;id&quot;, &quot;subject&quot;), array('empty'=&gt;'select subject')) ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'subject'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'teacher'); ?&gt;


	&#60;&#33;--&lt;?php echo &#036;form-&gt;textField(&#036;model,'teacher',array('size'=&gt;25,'maxlength'=&gt;25)); ?&gt;--&#62;


	&lt;?php echo &#036;form-&gt;dropDownList(&#036;model,'teacher', CHtml::listData(masterFaculty::model()-&gt;findAll(), &quot;id&quot;, &quot;teacher&quot;), array('empty'=&gt;'select teacher')) ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'teacher'); ?&gt;


&lt;/div&gt;

i need the subject values to reflect in teachers dropdown…

Hi BICKY, welcome to the forum.

Doesn’t this wiki article help you?

http://www.yiiframework.com/wiki/24/creating-a-dependent-dropdown

As you are using an active form, the view code will be like this:




<div class="row">

	<?php echo $form->labelEx($model,'subject'); ?>

	<?php echo $form->dropDownList($model,'subject',

		CHtml::listData(masterSubject::model()->findAll(), "id", "subject"),

		array(

			'empty'=>'select subject',

			'ajax'=>array(

				'type'=>'POST',

				'url'=>CController::createUrl('myController/getTeachers'),

				'update'=>'#'.CHtml::activeId($model, 'teacher')

			),

		)) ?>

	<?php echo $form->error($model,'subject'); ?>

</div>


<div class="row">

	<?php echo $form->labelEx($model,'teacher'); ?>

	<?php echo $form->dropDownList($model,'teacher',

		array(), // initially empty

		array('empty'=>'select teacher')) ?>

	<?php echo $form->error($model,'teacher'); ?>

</div>