예제 #1
0
 /**
  * @Route("/edit", name="edit")
  * @Request({"id": "int"})
  */
 public function editAction($id = 0)
 {
     $formmaker = App::module('bixie/formmaker');
     if (!($form = Form::find($id))) {
         $form = Form::create();
     }
     if (!$form) {
         throw new NotFoundException(__('Form not found.'));
     }
     return ['$view' => ['title' => __('Form'), 'name' => 'bixie/formmaker/admin/edit.php'], '$data' => ['config' => $formmaker->config(), 'types' => $formmaker->getFieldTypes(), 'formitem' => $form]];
 }
예제 #2
0
 /**
  * @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'] = App::filter($data['slug'] ?: $data['title'], 'slugify'))) {
         App::abort(400, __('Invalid slug.'));
     }
     try {
         $form->save($data);
     } catch (Exception $e) {
         App::abort(400, $e->getMessage());
     }
     return ['message' => 'success', 'formitem' => $form];
 }