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’),
array(
‘class’=>‘form-control’,
‘prompt’=>‘Choose you university’,
‘ajax’=>array(
‘type’=>‘POST’,
‘url’ => CController::createUrl(‘findcourses’),
‘data’=> array(‘uni_name’=>‘js:this.value’),
‘update’=>’#course_name’,))
);
?>
<?php echo CHtml::dropDownList(‘course_name’,’’, array(),
array(‘prompt’=>‘Choose course’,‘class’=>‘form-control’)); ?>
Here is my CoursesController.php
public function actionFindcourses()
{
$data = Courses::model()->findAll('uni_id=:uni_name',
array(':uni_name'=>$_POST['uni_name']));
$data=CHtml::listData($data,'course_id','course_name');
echo "<option value=''>Courses</option>";
foreach($data as $value=>$name)
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($name),true);
}
Here i got this error when i try to add new course
CException
Property "Courses.uni_name" is not defined.