コード例 #1
0
 /**
  * @Route("/", methods="POST")
  * @Route("/{id}", methods="POST", requirements={"id"="\d+"})
  * @Request({"file": "array", "id": "int"}, csrf=true)
  */
 public function saveAction($data, $id = 0)
 {
     /** @var File $file */
     if (!$id || !($file = File::where(compact('id'))->related('categories')->first())) {
         if ($id) {
             App::abort(404, __('File not found.'));
         }
         $file = File::create();
     }
     if (!($data['slug'] = App::filter($data['slug'] ?: $data['title'], 'slugify'))) {
         App::abort(400, __('Invalid slug.'));
     }
     $file->save($data);
     $file->saveCategories($data['category_ids']);
     return ['message' => 'success', 'file' => $file];
 }
コード例 #2
0
 /**
  * @Route("/file/edit", name="file/edit")
  * @Access("download: manage downloads")
  * @Request({"id": "int"})
  */
 public function editAction($id = 0)
 {
     try {
         if (!($file = File::where(compact('id'))->related('categories')->first())) {
             if ($id) {
                 App::abort(404, __('Invalid file id.'));
             }
             $file = File::create(['status' => 1, 'slug' => '', 'data' => [], 'tags' => [], 'date' => new \DateTime()]);
             $file->set('markdown', $this->download->config('markdown'));
         }
         return ['$view' => ['title' => $id ? __('Edit download') : __('Add download'), 'name' => 'bixie/download/admin/file.php'], '$data' => ['categories' => Category::findAll(), 'statuses' => File::getStatuses(), 'roles' => array_values(Role::findAll()), 'config' => $this->download->config(), 'file' => $file, 'tags' => File::allTags()], 'file' => $file];
     } catch (\Exception $e) {
         App::message()->error($e->getMessage());
         return App::redirect('@download/download');
     }
 }