Пример #1
0
 public function upload()
 {
     if ($this->validate()) {
         $cat = Categories::findOne($this->id);
         $contr = Yii::$app->controllerNamespace . '\\' . ucfirst($cat->handler) . 'Controller';
         $base = $contr::baseStorePath();
         $store_to = $base['real'] . $cat->route;
         foreach ($this->files as $f) {
             $new_fn = $this->newFileName($f->baseName, $f->extension);
             if ($f->saveAs($store_to . $new_fn)) {
                 $res = new Resources();
                 $res->attachBehavior('ImageBehavior', ['class' => ImageBehavior::className()]);
                 $res->category_id = $this->id;
                 $res->title = $res->description = $f->baseName;
                 $res->keywords = $new_fn;
                 //реальное имя файла с расширением
                 $res->alias = str_replace('.' . $f->extension, '', $new_fn);
                 //псевдоним изначально равен имени файла
                 $res->path = $store_to;
                 $res->webroute = $base['web'] . $cat->route;
                 $res->filename = $new_fn;
                 $res->save();
             }
             //TODO обработка ошибки сохранения файла
         }
         return true;
     }
     return false;
 }
Пример #2
0
 /**
  * Creates a new Resources model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Resources();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #3
0
 /**
  *   Создание новой страницы в категории $id.
  */
 public function actionCreate($id)
 {
     $model = new Resources();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['list', 'id' => $id]);
     } else {
         $model->category_id = $id;
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #4
0
 public function actionNewAlbum($id)
 {
     if ($id == 0) {
         throw new BadRequestHttpException("Неправильный запрос");
     }
     $model = new Resources(['scenario' => 'album']);
     $model->category_id = $id;
     $model->attachBehavior('createStoreDir', ['class' => StoreDirBehavior::className(), 'handlerName' => $this->id]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['list', 'id' => $model->id]);
     } else {
         return $this->render('new-album', ['model' => $model]);
     }
 }