I am tasked to change the database and access some of the attributes of a new table.
I have created the table "tag" as well as a table in between called "dashboard_has_tag" as the tables "dashboard" and "tag" are in a many-to-many relationship to each other.
Now I need to know, how I can access the attributes (namely the tag as well as idtag) from a view. I have instantiated the model (dashboard) already. Is there a way to do this?
Here is a picture of the tables with the relations
Yii makes this rather easy. By using $model->table_name->column
, you can access items in the related tables, as long as the models are setup for this. For instance, to access from dashboard to tag and idtag, $dashboard->dashboard_has_tag->tag->tag
should get you the tag's text, and similarly, $dashboard->dashboard_has_tag->tag->idtag
should get you the tag's ID.
If you use Gii to create your models, they should be setup for this.