/**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = GroupCourse::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #2
0
<div>
<?php 
$groupCourse = GroupCourse::model()->findByAttributes(array('courseId' => $courseId, 'groupId' => $data->id));
if ($groupCourse) {
    echo CHtml::ajaxLink(Yii::t('app', '取消收藏'), array('groupCourse/delete', 'id' => $groupCourse->id), array('type' => 'post', 'success' => 'js:function(data){window.location.reload();}'), array('class' => 'btn pull-right'));
} else {
    echo CHtml::ajaxLink(Yii::t('app', '收藏'), array('groupCourse/create', 'groupId' => $data->id, 'courseId' => $courseId), array('success' => 'js:function(data){window.location.reload();}'), array('class' => 'btn  btn-success pull-right'));
}
echo $data->name;
?>
<div class="clearfix"></div>
</div>
 /**
  * ToggleCourse
  * @param integer $id
  * @param integer $courseId
  */
 public function actionToggleCourse($id, $courseId)
 {
     $group = $this->loadModel($id);
     $course = Course::model()->findByPk($courseId);
     if ($course) {
         $groupCourse = new GroupCourse();
         $groupCourse->groupId = $id;
         $groupCourse->courseId = $courseId;
         $groupCourse->addTime = time();
         $groupCourse->userId = Yii::app()->user->id;
         if ($groupCourse->save()) {
             Yii::app()->user->setFlash('success', '');
         }
     }
 }