0

I am generating Models and CRUD for my database tables using giix in YII web framework, the thing is I want to change some of the attributes that showed to me but I dont know how ? I get into the code _FORM.php of the generated CRUD to one of the table and I knew the piece of code that I must change it to get a different attribute instead of one that shown to me without knowing why ?

    <div class="row">
    <?php echo $form->labelEx($model,'idEmployee'); ?>
    <?php echo $form->dropDownList($model, 'idEmployee', GxHtml::listDataEx(Employee::model()->findAllAttributes(null, true))); ?>
    <?php echo $form->error($model,'idEmployee'); ?>
    </div><!-- row -->

in the previous code the form showed a drop-down list from another table jointed with the current table according to idEmployee, he's showing an attribute that I dont want, I want to know how to render the FirstName and the LastName in the drop-down list, any help please ?

1 Answers1

1

I believe it is easier when you just create your own dropdown list provider

in the Employee.php you add these two functions:

public function getFullName()
{
    return $this->first_name.' '.$this->last_name; // or what ever you want to be shown on the drop list
}


public static function getNamesList() {
    return CHtml::listData(self::model()->findAll(), 'idEmployee', 'fullName');
}

in the _FORM.php write:

<div class="row">
<?php echo $form->labelEx($model,'idEmployee'); ?>
<?php echo $form->dropDownList($model, 'idEmployee', Employee::getNamesList()); ?>
<?php echo $form->error($model,'idEmployee'); ?>
</div><!-- row -->
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Nour Wolf
  • 2,140
  • 25
  • 24
  • Maybe you may replace the CHtml::listData with the GxHtml::listDataEx from the original question and still will works because GxHtml extends from CHtml. – javijuol May 17 '13 at 17:27