Yii Framework Forum: Add New Property In Model File Of A Active Record In Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Add New Property In Model File Of A Active Record In Yii Rate Topic: -----

#1 User is offline   hamir 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 28-December 12

Posted 28 December 2012 - 09:26 AM

I am new in Yii framework and have a question.

I have a table named 'node' which has these fields:

id
name
parent_id

parent_id contain id of parent of a node which exist in this table too.

I have created model,controller and view files using Gii interface. In view files id of parent is shown but I want to display parent name instead of its id .

I guess maybe I need to add a public property in model class of this table, so I would be access to it via ->parent_name in view files.

How can I do it ? what files should I change ?
0

#2 User is offline   Hyprion 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 07-October 09
  • Location:Netherlands

Posted 28 December 2012 - 09:32 AM

create a relation with name "parentNode" and then you can use $model->parentNode->name; in your views
0

#3 User is offline   hamir 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 28-December 12

Posted 28 December 2012 - 09:43 AM

View PostHyprion, on 28 December 2012 - 09:32 AM, said:

create a relation with name "parentNode" and then you can use $model->parentNode->name; in your views



Thank you.
How can I involve it in controller to have it in views that user $dataProviders?
I mean how can I return it in ActiveDataProvider for example to have it in index and admin view files ?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users