/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($bookId = null, $seriesId = null)
 {
     $model = new Comment();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Comment'])) {
         $_POST['Comment']['author'] = Yii::app()->user->name;
         $_POST['Comment']['date'] = date('d M Y H:i:s');
         $model->attributes = $_POST['Comment'];
         if ($model->save()) {
             if (isset($bookId)) {
                 $commentsBooks = new CommentsBooks();
                 $commentsBooks->commnet_id = $model->id;
                 $commentsBooks->book_id = $bookId;
                 $commentsBooks->save();
                 $this->redirect(array('book/view/' . $bookId));
             }
             if (isset($seriesId)) {
                 $commentsSeries = new CommentsSeries();
                 $commentsSeries->comment_id = $model->id;
                 $commentsSeries->series_id = $seriesId;
                 $commentsSeries->save();
                 $this->redirect(array('series/view/' . $seriesId));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  * 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
  * @return CommentsSeries the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = CommentsSeries::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }