0
votes

What i have: 1 'user' table (id, username) with 'user' model 1 'date' table (id, user_id, date) with 'date' model Each user can have one or more dates.

I have view with TbExtendedGridView (bootstrap CGridView) widget that needs to show list of users (each user 1 row) and users dates.

I have set up relations inside model and in database.

When i try to display dates for each user by simply telling view to show data from date relation, it throws and error that array needs to be string. I understand that, as one user has many dates, it will give those dates in array.

What i did next is i created function inside date column's 'value' which uses foreach loop and echoes all dates.

My question is, how do i move that function out of the view to model, and to which model do i move it? Leaving it inside view just feels simply wrong.

I'd appreciate suggestion how to deal with this. I need every user in 1 row. One cell username, one cell dates for that username.

1

1 Answers

0
votes

my suggestion is to move it to the user model and name it for example getDatesDetails() that should return whatever string you need and in your column you can user 'value'=>'$data->getDatesDetails()' or 'value'=>'datesDetails'