Esempio n. 1
0
 public function actionCreate()
 {
     $model = new Dynamic();
     if ($_POST['Dynamic']) {
         $accessKey = Yii::app()->params['qiniu']['accessKey'];
         $secretKey = Yii::app()->params['qiniu']['secretKey'];
         $auth = new Auth($accessKey, $secretKey);
         $bucket = 'urtime1';
         $token = $auth->uploadToken($bucket);
         $uploadMgr = new UploadManager();
         $_POST['Dynamic']['dy_type'] = 2;
         /*var_dump($_POST['Dynamic']);
           var_dump($_FILES);
           exit;*/
         if ($_FILES['upImage']['name'] != null) {
             $images = $this->setImageInformation($_FILES, $token, $uploadMgr);
             if ($images) {
                 //$images_str = implode(',',$images);
                 $_POST['Dynamic']['dy_images'] = json_encode($images);
                 //$images_str;
             }
         }
         $model->attributes = $_POST['Dynamic'];
         if ($model->validate() && $model->save()) {
             //$this->redirect('site/index');
             Yii::app()->user->setFlash('dynamic', '创建成功');
             // Yii::app()->end();
             $this->redirect(array('/dynamic/index'));
         }
     }
     $stores = Store::model()->getName();
     $this->render('create', ['model' => $model, 'stores' => $stores]);
 }
Esempio n. 2
0
 public function addDynamic($params = array())
 {
     extract($params);
     if (isset($id) && $id && isset($type)) {
         $dynamic = array('dy_user' => $id, 'dy_type' => $type ? $type : 0);
         if (isset($content) && $content) {
             $dynamic['dy_content'] = $content;
         }
         if (isset($image) && $image) {
             if (!is_null(json_decode($image))) {
                 $images = json_decode($image);
                 $dynamic['dy_images'] = implode(',', $images);
             } else {
                 $dynamic['dy_images'] = $image;
             }
         }
         $model = new Dynamic();
         $model->attributes = $dynamic;
         if ($model->validate() && $model->save()) {
             $id = $model->getPrimaryKey();
             $result = array('id' => $id);
             $ret = $this->notice('OK', 0, '成功', $result);
         } else {
             $ret = $this->notice('ERR', 307, '操作数据错误', $model->getErrors());
         }
         return $ret;
     } else {
         return $this->notice('ERR', 301, '缺少关键参数', []);
     }
 }