Пример #1
0
 /**
  * @Route("/edit", name="edit")
  * @Request({"id": "int"})
  */
 public function editAction($id = 0)
 {
     $formmaker = App::module('formmaker');
     if (!($form = Form::find($id))) {
         $form = Form::create();
     }
     if (!$form) {
         throw new NotFoundException(__('Form not found.'));
     }
     return ['$view' => ['title' => __('Form'), 'name' => 'formmaker:views/admin/edit.php'], '$data' => ['config' => $formmaker->config(), 'types' => $formmaker->getTypes(), 'formitem' => $form]];
 }
 /**
  * @Route("/", methods="POST")
  * @Route("/{id}", methods="POST", requirements={"id"="\d+"})
  * @Request({"formitem": "array", "id": "int"}, csrf=true)
  */
 public function saveAction($data, $id = 0)
 {
     if (!($form = Form::find($id))) {
         $form = Form::create();
         unset($data['id']);
     }
     if (!($data['slug'] = $this->slugify($data['slug'] ?: $data['title']))) {
         App::abort(400, __('Invalid slug.'));
     }
     try {
         $form->save($data);
     } catch (Exception $e) {
         App::abort(400, $e->getMessage());
     }
     return ['message' => 'success', 'formitem' => $form];
 }