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
Add this in the employee grid view’s
columnsattribute: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
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:
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.