Jump to content
Larry Ullman's Book Forums

mcmurphy510

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by mcmurphy510

  1. Thanks for the reply Larry.
     
    Here are my relations:
    From Employee.php:

    'department' => array(self::BELONGS_TO, 'Department', 'departmentId')

    From Department.php:

    'employees' => array(self::HAS_MANY, 'Employee', 'departmentId')

     
    It looks like my problem was in the view code.  For employee/admin.php I had:

    $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'employee-grid',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>array(
            'id',
            'departmentId',
            'firstName',
            'lastName',
            'email',
            'ext',
            array(
                'class'=>'CButtonColumn',
            ),
        ),
    ));

    Which I have replaced with:

        ...
        'columns'=>array(
            'id',
            'department.name',
            ...

    Is this the best way of going about this?

    It is now showing the department name, but it's showing the column name as "Name" rather than Department and search functionality is also gone for that column.

     

    Here's a screen cap of what it's doing:

    1heni.jpeg

    Thanks again.

  2. Hi,
     
    I got all the way through the tutorial with no problems until the very end.
     
    In “EmployeeController.php” I’m trying to get yii to display the relation for department rather than the ID number. I have tried this code in the loadModel method:

    $model=Employee::model()->with('department')->findByPk((int)$id);

    I have double checked all of my relations and they all seem to be in order.

     

    It’s still showing the ID number rather than the department name.
     

    Any ideas?

     

    Thanks

×
×
  • Create New...