Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:22:01+00:00 2026-06-05T07:22:01+00:00

i just started with yii, but i’m not new to php framework. however right

  • 0

i just started with yii, but i’m not new to php framework. however right now i’m stuck with this problem:

I’ve two Models/Databases:

Department:
http://s7.directupload.net/images/120610/alemicys.png

Employee:
http://s1.directupload.net/images/120610/hxerdm8t.png

I simply want to show the actual name of the Department in this Employee-view. So that instead of the 1 in column “Department” i would like to have “Department of Justice”.

This is what my databases look like:
http:// s1.directupload.net/images/120610/7wupindz.png

Thanks in advance!
John

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:22:02+00:00Added an answer on June 5, 2026 at 7:22 am

    Add this in the employee grid view’s columns attribute:

    // this is in place of just 'departmentId',
    array( 
        'name'=>'departmentId', // name of the foreign key attribute
        'value'=>'$data->department->name', // access the 'name' attribute of the related record through relation named 'department', the current record is represented by '$data'
        'type'=>'raw' // data is of raw type
    ),
    

    Read up on CDataColumn to know how to modify the above array.

    Note: Since you only asked for display, the above code will work, if you want the filter for this column to work, you’ll have to either

    1. modify the search function of the employee model(or wherever you are doing the search) to map the input string to a departmentId or
    2. write some javascript to send the related department’s id to the search, instead of a string.

    Right now the filter will only work with departmentId(i.e integer) not name(string).

    You can also do this instead of the code above:

    //again in place of departmentId
    'department.name' // using the 'department' relation, accessing its 'name'
    

    But then to get the filter will be tough(you’ll have to use an array again), and the column header will also become the attributeLabel of Department model’s name attribute. Header can be changed by using the format : 'name:type:header' , so you can do: 'department.name:Department'

    Most of these details are available in the documentation links i have included.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Yii framework and just started to work on an existing
I just started developing my new project in Yii, I am new to Yii
Just started learning PySide and is having problem with QTimer I have this #!/usr/bin/python
Just started using Blueprint CSS and now playing with the grids but have a
I just started using the Yii framework and I'm having some trouble with it.
Just started using App Engine's webapp framework, but I can't figure out what's wrong
Just started a new job, working with the zend framework, the project is essentially
Just started with media wiki but i have a weird problem. I want to
Just started working with .NET and MVC(1). I'm having a problem wherein in my
Just started learning Groovy, got the PragProg book Programming Groovy and had a problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.