/**
  * Creates new gallery section using model attributes.
  * @return boolean
  */
 public function create($parent_id)
 {
     if (!$this->validate()) {
         return false;
     }
     $parent = Gallery::findOne($parent_id);
     if ($parent === null) {
         $parent = Gallery::find()->roots()->one();
     }
     if ($parent === null) {
         return false;
     }
     $this->object = $object = new GallerySection(['title' => $this->title]);
     if (!$object->appendTo($parent, false)) {
         return false;
     }
     $object->makeAlias();
     $object->update(false, ['alias']);
     return true;
 }
示例#2
0
 /**
  * Gallery section updating.
  * @param integer $id Gallery section id.
  * @return void
  */
 public function actionUpdate($id)
 {
     $object = GallerySection::findOne($id);
     if ($object === null) {
         throw new BadRequestHttpException(Yii::t('gallery', 'Section not found.'));
     }
     $model = new GallerySectionForm(['object' => $object]);
     if ($model->load(Yii::$app->getRequest()->post()) && $model->update()) {
         Yii::$app->session->setFlash('success', Yii::t('gallery', 'Changes saved successfully.'));
         return $this->redirect(['index', 'id' => $model->object->id]);
     }
     return $this->render('update', ['model' => $model]);
 }