Yii Framework Forum: Issue With Drop Down List - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Issue With Drop Down List Rate Topic: -----

#1 User is offline   FresherInYII 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 27-February 13
  • Location:Sri-Lanka

Posted 25 March 2013 - 10:05 AM

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'); ?>
<?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...
Thankz! Cheerz!
:)!
0

#2 User is offline   jhonka 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 22-June 12

Posted 25 March 2013 - 11:02 AM

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.
0

#3 User is offline   codesutra 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 362
  • Joined: 15-March 11
  • Location:India

Posted 25 March 2013 - 11:39 AM

View PostFresherInYII, on 25 March 2013 - 10:05 AM, said:

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'); ?>
<?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...
Thankz! Cheerz!
:)!



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.:)
CodeSutra
0

#4 User is offline   FresherInYII 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 27-February 13
  • Location:Sri-Lanka

Posted 25 March 2013 - 12:22 PM

View Postjhonka, on 25 March 2013 - 11:02 AM, said:

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.


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

#5 User is offline   FresherInYII 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 27-February 13
  • Location:Sri-Lanka

Posted 25 March 2013 - 12:30 PM

View Postcodesutra, on 25 March 2013 - 11:39 AM, said:

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.:)


@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">
<?php echo $form->labelEx($model,'selected_grade'); ?>
<?php
$current_val=$model->getGrades();
echo $myval=$form->dropDownList($model, 'grade',$current_val ,
array('style' => 'width:200px;'));
?>
<?php echo $form->error($model,'grade'); ?>

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

<?php echo $form->labelEx($model,'class'); ?>
<?php $choosen_grade=5;
echo $form->dropDownList($model, 'class',
array('class'=>$model->getClasses($choosen_grade)), array('style' => 'width:200px;')); ?>
<?php echo $form->error($model,'class'); ?>
</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! :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users