Accessing parent class attributes/functions in view (index)

Got a Members class and MembersSearch class (gii generated).

The members class has a relation with a group class

<php>

public function getGroup() {

return $this->hasOne(Group::className(),[‘groupid’=>‘groupid’]); }

in view(index) how would i get a groups attribute, name to Display like "Members of groupX"

Tried this in index.php $this->title = 'Members of '.$this->Members->group->name();

</php>

What does your controller action look like?

<php>

&#036;searchModel = new MembersSearch(); 		&#036;dataProvider = &#036;searchModel-&gt;search(Yii::&#036;app-&gt;request-&gt;queryParams,&#036;groupid = 'groupid');

return $this->render(‘index’, [ ‘searchModel’ => $searchModel, ‘dataProvider’ => $dataProvider, ]);

</php>

And in your index you have a gridview and you want to show an additional column?

Maybe have a look at this:

http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#relational-data

In a Gii-generated view the object passed from the controller is usually named [font="Courier New"]$model[/font]. Assuming in your view [font="Courier New"]$model[/font] is an instance of [font="Courier New"]Member[/font] then [font="Courier New"]$model->group->name[/font] is probably what you want.

If you are trying to access the group name in a grid then you can use “dot notation” as shown here. If I understand your case, you can use [font=“Courier New”]‘group.name’[/font] as an attribute name.

See also the [font="Courier New"]$value[/font] and [font="Courier New"]$content[/font] properties of DataColumn