コード例 #1
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');
     }
 }