Issue With Drop Down List

Hello everyone,

Im new to YII, and i’m facing this issue when customizing the _form of my view Recordbook:

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

	&lt;?php 


            &#036;teacher_id='AC0001';//hardcoded the value for testing


            echo &#036;form-&gt;dropDownList(&#036;model, 'subject', &#036;model-&gt;getSubjects(&#036;teacher_id), array('style' =&gt; 'width:200px;')); ?&gt;

<?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){

        &#036;list= Yii::app()-&gt;db-&gt;createCommand('select distinct classId from schoolclasses where grade='.&#036;grade.'')-&gt;queryAll();





        &#036;rs=array();


            foreach(&#036;list as &#036;item){


            &#036;rs[]=&#036;item['classId'];


            }


        return &#036;rs;

}

Is there anything wrong with this? i dont see why… please help…

Thankz! Cheerz!

:)!

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.

What i am guessing from your post is, you are getting issue to show a selected option in dropdown list. is it right ?/

If yes then here is the reference

for it. So let it try,i am sure you will get more option here also.:)

@jhonka - Thank you very much, yup that definitely was the issue. :)…! Cheerz!

@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…

i.e. in my view:-

<div class="row">

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


	&lt;?php


            &#036;current_val=&#036;model-&gt;getGrades();


            echo &#036;myval=&#036;form-&gt;dropDownList(&#036;model, 'grade',&#036;current_val ,     


            array('style' =&gt; 'width:200px;')); 


            ?&gt;


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

Here the selected value of grade has to be the parameter to my next method…

<?php echo $form->labelEx($model,‘class’); ?>

	&lt;?php &#036;choosen_grade=5; 


            echo &#036;form-&gt;dropDownList(&#036;model, 'class', 


                    array('class'=&gt;&#036;model-&gt;getClasses(&#036;choosen_grade)), array('style' =&gt; 'width:200px;')); ?&gt;


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

</div>

i think its a bit of AJAX involved in it… but cant figure it out… im no big shot in AJAX too…

Any help is appreciated… Thanks a lot…

Cheerz! :)