public function addCategoryAction(Request $request) { $category = new Category(); $action = new AddCategoryAction($this->app); $retrieveAction = new RetrieveCategoryAction($this->app); $form = $this->app['form.factory']->create(new AddCategory(), $category); if ($request->getMethod() == "POST") { $form->handleRequest($request); if ($form->isValid()) { $action->handle($category); $categories = $retrieveAction->handle(); return $this->app['twig']->render('admin/addCategory.twig', ['form' => $form->createView(), 'categories' => $categories]); } } $categories = $retrieveAction->handle(); return $this->app['twig']->render('admin/addCategory.twig', ['form' => $form->createView(), 'categories' => $categories]); }
public function editcategoryAction(Request $request, $slug) { $category = new Category(); $retrieveAction = new RetrieveCategoryAction($this->app); $editAction = new EditCategoryAction($this->app); $data = $retrieveAction->handle($slug); $form = $this->app['form.factory']->create(new CategoryForm(), $category); if ($request->getMethod() == "POST") { $form->handleRequest($request); if ($form->isValid()) { $editAction->handle($category, $data[0]); return $this->app->redirect($this->app["url_generator"]->generate("addCategory")); } } return $this->app['twig']->render('admin/editCategory.twig', ['form' => $form->createView(), 'slug' => $data[2], 'nama' => $data[1], 'value' => "Edit category", 'requestCount' => GetBorrowRequestCountHelper::help(), 'countOfBorrowing' => GetCountOfBookInBorrowingHelper::help()]); }