Yii Framework Forum: How To Create A 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

How To Create A Drop Down List

#1 User is offline   pro_net 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 26-August 13

Posted 03 October 2013 - 02:41 AM

I have two tables student,and student group. In student table there has student group_id, which is foreign key of Student group table. Now i want a list where group name will be drop down and ASC order.

In the _form page of student folder write code

<div class="row">
<?php echo $form->labelEx($model,'Group_ID'); ?>
<?php echo $form->dropDownList($model,'StudentGroup', CHtml::listData(StudentGroup::model()->findAll(), 'Group_Id', 'Group_Name'), array('empty'=>'Select location'));?>
<?php echo $form->error($model,'Group_ID'); ?>

It shows the following error
Property "student.studentGroup" is not defined.

how to solve this.

Please help me as soon as possible.

#2 User is offline   Abhishek Shah 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 89
  • Joined: 20-July 12
  • Location:New Jersey,USA

Posted 03 October 2013 - 06:02 AM

In dropdown you have,take studentgroup as a second parameter,why?
There is no field name with name studentgroup,in student model,so it is obvous error.
You should take Group_ID,& also change 'empty'=>'select group' ::)
This way,it will work.
Feel free to ask for help,
Yii Basic Gii With Export Pdf Excel

#3 User is offline   Balu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 09-August 11
  • Location:Kerala, India

Posted 05 October 2013 - 05:14 AM

Try like this
<?php echo $form->dropDownList($model,'article', RefArticleEquipment::getArticle()); ?>

public static function getArticle(){
    $prov1 = RefSupply::model()->findAll();
    $data1 = CHtml::listData($prov1, 'id', 'article_code');

    $prov2 = RefEquipment::model()->findAll();             
    $data2 = CHtml::listData($prov2, 'id', 'article_code');

    return array_merge($data1, $data2); 

this may help for your solution

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