コード例 #1
0
 /**
  * @Route("/", methods="POST")
  * @Route("/{id}", methods="POST", requirements={"id"="\d+"})
  * @Request({"project": "array", "id": "int"}, csrf=true)
  */
 public function saveAction($data, $id = 0)
 {
     if (!$id || !($project = Project::find($id))) {
         if ($id) {
             App::abort(404, __('Post not found.'));
         }
         $project = Project::create();
     }
     if (!($data['slug'] = App::filter($data['slug'] ?: $data['title'], 'slugify'))) {
         App::abort(400, __('Invalid slug.'));
     }
     $project->save($data);
     return ['message' => 'success', 'project' => $project];
 }
コード例 #2
0
 /**
  * @Route("/project/edit", name="project/edit")
  * @Access("portfolio: manage portfolio")
  * @Request({"id": "int"})
  */
 public function editAction($id = 0)
 {
     try {
         if (!($project = Project::where(compact('id'))->first())) {
             if ($id) {
                 App::abort(404, __('Invalid project id.'));
             }
             $module = App::module('bixie/portfolio');
             $project = Project::create(['data' => [], 'tags' => [], 'date' => new \DateTime()]);
             $project->set('markdown', $module->config('markdown'));
         }
         return ['$view' => ['title' => $id ? __('Edit Project') : __('Add Project'), 'name' => 'bixie/portfolio/admin/project.php'], '$data' => ['config' => App::module('bixie/portfolio')->config(), 'project' => $project, 'tags' => Project::allTags()], 'project' => $project];
     } catch (\Exception $e) {
         App::message()->error($e->getMessage());
         return App::redirect('@portfolio/post');
     }
 }