Hi all,
I’m trying to build an action where you can view all the groups where the current user belongs to. I would like to know the best way to do it.
The tables I have are the following:
CREATE TABLE IF NOT EXISTS `tbl_group` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) COLLATE utf8_spanish_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
)
CREATE TABLE IF NOT EXISTS `tbl_member` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`group_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`is_admin` tinyint(4) NOT NULL,
`is_creator` tinyint(4) NOT NULL,
`join_time` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `MEMBER_GROUP_USR` (`friendgroup_id`,`user_id`)
)
The other table is the typical tbl_user.
The Group class relations array is:
public function relations()
{
return array(
'members' => array(self::HAS_MANY, 'Member', 'group_id'),
'memberCount' => array(self::STAT, 'Member', 'group_id'),
);
}
Member relationship:
public function relations()
{
return array(
'groups' => array(self::BELONGS_TO, 'FriendGroup', 'friendgroup_id'),
);
}
User relationship:
public function relations()
{
return array(
'memberOf' => array(self::HAS_MANY, 'Member', 'user_id'),
);
}
The question is how to write the code in the controller action in order to view all the groups (table tbl_group) where the user is a member. I would like to use the zii.widgets.CListView so I’ll need to pass a CActiveDataProvider. I don’t know if this is possible (in this case I don’t know how to do it) or I should do it another way.
Thanks in advance.