Problem With Dependent Dropdown List

Hi, I want to create dependent DropDownList.

This are my tables form database.

Universities- uni_id(PK), uni_name;

Courses- course_id(PK),course_name,uni_id(FK).

I have dropdownlist University and Courses.

when university is selected ,course offering by that university is list in courses dropdown list.

Pls help

my view/courses/_form.php code is here

<?php echo $form->dropDownList($model,‘uni_name’,CHtml::listData(Universities::model()->findAll(

array(‘order’ => ‘uni_id’)),‘uni_id’,‘uni_name’),



‘prompt’=>‘Choose you university’,



‘url’ => CController::createUrl(‘findcourses’),

‘data’=> array(‘uni_name’=>‘js:this.value’),




<?php echo CHtml::dropDownList(‘course_name’,’’, array(),

array(‘prompt’=>‘Choose course’,‘class’=>‘form-control’)); ?>

Here is my CoursesController.php

public function actionFindcourses()


    &#036;data = Courses::model()-&gt;findAll('uni_id=:uni_name',




    echo &quot;&lt;option value=''&gt;Courses&lt;/option&gt;&quot;;

    foreach(&#036;data as &#036;value=&gt;&#036;name)

        echo CHtml::tag('option', array('value'=&gt;&#036;value),CHtml::encode(&#036;name),true);


Here i got this error when i try to add new course


Property "Courses.uni_name" is not defined.

Yii internally tries to use undefined property uni_name with courses table. Yii throws this exception because in courses table no such a column named uni_name so that it happens

you may try this

public function actionFindcourses()


		$criteria = new CDbCriteria();

		$criteria->condition = 'uni_id = :uni_id';

		$criteria->params = array(':uni_id'=>$_POST['uni_name']);


		$courses = Courses::model()->findAll($criteria);

		$options = "<option value=''>Courses</option>";


		foreach($courses as $course)

			$options . = "<option value=\"$course->course_id\" >$course->course_name</option>";


		echo $options;


In the above $model seems to be an instance of Courses model. But it should be that of Universities.

hey tried some different and it worked

Thank u…