pro_net
(Pradosh Global)
October 3, 2013, 7:32am
1
Hi,
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'); ?>
</div>
It shows the following error
Property "student.StudentGroup" is not defined.
how to solve this.
Please help me as soon as possible.
prat
(Yurfriend19)
October 3, 2013, 11:03am
2
what is the name of your model file is it StudentGroup.php? Hope so you are not making mistake in upper/lower case. Since you want to arrange them in ASC order define $criteria something like this
<?php echo $form->dropDownList($model,'StudentGroup', CHtml::listData(StudentGroup::model()->findAll(array('order' => 'Group_Name ASC'), 'Group_Id', 'Group_Name'), array('empty'=>'Select location'));?>
instead of $model, ‘StudentGroup’ it should be $model, ‘Group_Id’ or ‘Group_Name’
sylvainb
(Sylvain Briat)
October 3, 2013, 11:11am
3
Hi,
i think it’s because Yii tries to find the field ‘StudentGroup’ in your model
try to replace it by student Group_Id :
<?php echo $form->dropDownList($model,'Group_Id', CHtml::listData(StudentGroup::model()->findAll(), 'Group_Id', 'Group_Name'), array('empty'=>'Select location'));?>
and eventually change its label in your student model :
public function attributeLabels()
{
return array(
'...' => '...',
'Group_Id' => 'Student Group',
);
}