コード例 #1
0
ファイル: PostController.php プロジェクト: tecshuttle/51qsk
 /**
  * 更新
  *
  * @param  $id
  */
 public function actionUpdate($id)
 {
     parent::_acl();
     $attr = $this->_gets->getParam('attr');
     $model = parent::_dataLoad(new Post(), $id);
     $imageList = $this->_gets->getParam('imageList');
     $imageListSerialize = XUtils::imageListSerialize($imageList);
     if (isset($_POST['Post'])) {
         $style = $this->_gets->getParam('style');
         $acl = $this->_gets->getParam('acl');
         $styleFormat = XUtils::titleStyle($style);
         $model->attributes = $_POST['Post'];
         $file = XUpload::upload($_FILES['attach'], array('thumb' => true, 'thumbSize' => array(400, 250)));
         if (is_array($file)) {
             $model->attach_file = $file['pathname'];
             $model->attach_thumb = $file['paththumbname'];
             $model->attach_status = 'Y';
             @unlink($_POST['oAttach']);
             @unlink($_POST['oThumb']);
         }
         $model->title_style = $styleFormat['text'];
         $model->title_style_serialize = $styleFormat['serialize'];
         $model->acl = is_array($acl) ? implode(',', $acl) : '';
         $model->image_list = $imageListSerialize['dataSerialize'];
         if ($model->save()) {
             Attr::xupdate($model->id, $attr);
             Post2tags::build('update', $_POST['Post']['tags'], $model->id, $model->catalog_id);
             AdminLogger::_create(array('catalog' => 'update', 'intro' => '编辑内容,ID:' . $id));
             $this->redirect(array('index'));
         }
     }
     $attrModel = Attr::lists($model->catalog_id, 'post');
     if ($attr) {
         $attrData = Attr::dataReset($attr);
     } else {
         $attrData = Attr::datas($model->id);
     }
     if ($imageList) {
         $imageList = $imageListSerialize['data'];
     } elseif ($model->image_list) {
         $imageList = unserialize($model->image_list);
     }
     $this->render('update', array('model' => $model, 'imageList' => $imageList, 'attrModel' => $attrModel, 'attrData' => $attrData, 'groupList' => $this->_groupList('user')));
 }