i am following this tutorial to create 2 dropdownlist depended on a master dropdownlist selected value
first, i want to select the cycle from the cycle list, and based on this value, the list of classes and subjects/periods must appear
this is my code:
in _form.php:
<?php
echo CHtml::dropDownList('CycleID','', CHtml::listData(Usersectionsecurity::model()->findAll(), 'Group_Code', 'E_Group_Desc'),
array(
'prompt'=>'Select Cycle',
));
echo CHtml::dropDownList('stclass', '', array());
echo $form->dropDownList($model,'periodID', array());
ECascadeDropDown::master('CycleID','Usersectionsecurity/getClassByCycle') //'controllerId/actionId'
->setDependent('stclass') //master for id_article with default options
->setDependent('periodID', //with custom labels
array('dependentStartingLabel'=>'Select Classes','dependentLoadingLabel'=>'Loading articles...'));
?>
in my controller:
public function actionGetClassByCycle()
{
ECascadeDropDown::checkValidRequest();
$type = Yii::app()->user->getType();
$userID = Yii::app()->user->getID();
if($type == 'Teacher'){
$model = Stclass::model()->GetClassOfUser($userID, ECascadeDropDown::submittedKeyValue());
}else{
$model=Usersectionsecurity::model()->findAll('Group_Code=\'' . ECascadeDropDown::submittedKeyValue() . '\'');
}
$models=Matiere::model()->GetMainSubjectByCycle(ECascadeDropDown::submittedKeyValue());
$data = array(
'CycleID' => CHtml::listData($model,'Class_Code', 'E_Class_Desc')
,
'stclass' => CHtml::listData($models,'Subject_Code', 'E_Subject_Name')
);
$masterId = ECascadeDropDown::submittedMasterId(); //master dropdownlist id_type or id_company
$masterKey = ECascadeDropDown::submittedKeyValue(); //the current key of the master
//$dependentId = ECascadeDropDown::submittedDependentId(); //if you need the dependent id
if(isset($data[$masterId][$masterKey]))
ECascadeDropDown::renderArrayData($data[$masterId][$masterKey]); //with Yii::app()->end()
ECascadeDropDown::renderEmptyData('-');
}
i made a var_dump($data), i get values but they not appears in the appropriate dr
array(2) {
["CycleID"]=>
array(3) {
[24]=>
string(7) "Grade 4"
[25]=>
string(7) "Grade 5"
[26]=>
string(7) "Grade 6"
}
["stclass"]=>
array(10) {
["020"]=>
string(28) "French as a Foreign Language"
["040"]=>
string(4) "Math"
["061"]=>
string(9) "Geography"
["062"]=>
string(7) "History"
["070"]=>
string(16) "Cultural Studies"
["080"]=>
string(6) "Civics"
["090"]=>
string(18) "Physical Education"
[110]=>
string(3) "Art"
[120]=>
string(5) "Drama"
[130]=>
string(5) "Music"
}
}
[{"value":"","label":"-"}]
where is my error. please help me