Beispiel #1
0
 /**
  * @Request({"id": "int", "type": "string"})
  */
 public function editAction($id = 0, $type = null)
 {
     if (!$id) {
         $widget = Widget::create(['type' => $type]);
     } else {
         if (!($widget = Widget::find($id))) {
             App::abort(404, 'Widget not found.');
         }
     }
     return ['$view' => ['title' => __('Widgets'), 'name' => 'system/widget/edit.php'], '$data' => ['widget' => $widget, 'config' => ['menus' => App::menu(), 'nodes' => array_values(Node::query()->get()), 'roles' => array_values(Role::findAll()), 'types' => array_values(App::widget()->all()), 'positions' => array_values(App::position()->all())]]];
 }
 /**
  * @Route("/", methods="POST")
  * @Route("/{id}", methods="POST", requirements={"id"="\d+"})
  * @Request({"widget": "array", "id": "int"}, csrf=true)
  */
 public function saveAction($data, $id = 0)
 {
     if (!$id) {
         $widget = Widget::create();
     } else {
         if (!($widget = Widget::find($id))) {
             App::abort(404, 'Widget not found.');
         }
     }
     $widget->save($data);
     return ['message' => 'success', 'widget' => $widget];
 }