Beispiel #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Replies();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Replies'])) {
         $model->attributes = $_POST['Replies'];
         if ($model->save()) {
             if ($model->attachments != null) {
                 $fileids = explode(",", $model->attachments);
                 for ($i = 1; $i < sizeof($fileids); $i++) {
                     $file = Files::model()->findByPk($fileids[$i]);
                     if ($file->uploadedby == Yii::app()->user->id) {
                         $file->objecttype = "Replies";
                         $file->objectid = $model->id;
                         $file->save();
                     }
                 }
             }
             //$this->redirect(array('view','id'=>$model->id));
             echo CJSON::encode(array('errors' => $model->getErrors(), 'redirect' => $this->createURL("/" . $model->content_type . "/view", array('id' => $model->content_type_id))));
             exit;
         }
     }
     if (!Yii::app()->request->isAjaxRequest) {
         $this->render('create', array('model' => $model));
     } else {
         if (array_key_exists('content_type_id', $_GET)) {
             $model->content_type_id = $_GET['content_type_id'];
         }
         if (array_key_exists('content_type', $_GET)) {
             $model->content_type = $_GET['content_type'];
         }
         $string = $this->renderPartial('_formajax', array('model' => $model), true, true);
         echo CJSON::encode(array('html' => $string, 'errors' => $model->getErrors()));
     }
 }