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 ?
You should have a relation to your parent node.
So in your Node::relations function, you should have something like:
To get this value from your child, you can do (assuming your child node variable is named $childNode):
If you really want to be able to do…
… for some reason, you can create a property in your Node model like this:
Now you can call…
OR
to get the name of the parent node.