Ejemplo n.º 1
0
 /**
  * Commentaries and answers edit action
  * @param string $type
  * @param int $id
  * @throws NotFoundException
  * @return string
  * @throws \Ffcms\Core\Exception\SyntaxException
  * @throws \Ffcms\Core\Exception\NativeException
  */
 public function actionEdit($type, $id)
 {
     // get active record by type and id from active records
     $record = null;
     switch ($type) {
         case static::TYPE_COMMENT:
             $record = CommentPost::find($id);
             break;
         case static::TYPE_ANSWER:
             $record = CommentAnswer::find($id);
             break;
     }
     // check if response is not empty
     if ($record === null || $record === false) {
         throw new NotFoundException(__('Comment is not founded'));
     }
     // init edit model
     $model = new FormCommentUpdate($record, $type);
     // check if data is submited and validated
     if ($model->send() && $model->validate()) {
         $model->make();
         App::$Session->getFlashBag()->add('success', __('Comment or answer is successful updated'));
     }
     // render view
     return $this->view->render('edit', ['model' => $model]);
 }