/** * 添加或取消关注 */ public function toggleCollect($userId) { $owner = $this->getOwner(); $collect = Collect::model()->findByAttributes(array('userId' => $userId, 'collectableEntityId' => $owner->entityId)); if ($collect) { $collect->delete(); return false; } else { $collect = new collect(); $collect->userId = $userId; $collect->collectableEntityId = $owner->entityId; $collect->addTime = time(); $collect->save(); return true; } }