Im new to YII, and i’m facing this issue when customizing the _form of my view Recordbook:
<?php echo $form->labelEx($model,‘subject’); ?>
<?php
$teacher_id='AC0001';//hardcoded the value for testing
echo $form->dropDownList($model, 'subject', $model->getSubjects($teacher_id), array('style' => 'width:200px;')); ?>
<?php echo $form->error($model,‘subject’); ?>
The method gets executed fine… but the selected value is not taken when stored to the DB…
I have overridden the beforeSave() and found out that the method executes fine…
model
public function getClasses($grade){
$list= Yii::app()->db->createCommand('select distinct classId from schoolclasses where grade='.$grade.'')->queryAll();
$rs=array();
foreach($list as $item){
$rs[]=$item['classId'];
}
return $rs;
}
Is there anything wrong with this? i dont see why… please help…
I might have misunderstood your question, but do you have a rule in your model’s class for subject? If you don’t have a rule for the attribute subject or haven’t assigned it to be a ‘safe’ variable, then the selected value won’t be assigned to $model when the form is submitted.
@codesutra - Thank you very much for the response, the thing is that ive been trying to pass the selected value of one drop down list as a parameter to another method which will populate another drop down list…