public function FormAction($id = '') { //set if ($id != '') { $action = 'update'; $data['action'] = 'update'; $data['category'] = Model::getById('cate', $id); } else { $action = 'add'; } $data['title'] = ''; $data['fullname'] = ''; //enter if ($input = $this->getPostData()) { $url = $this->app['slugify']->slugify($input['name']); $post = array('name' => $input['name'], 'target' => $url); if ($action == 'update') { $cate = Model::update('cate', $post, $id); } else { $cate = Model::add('cate', $post); } //check if ($cate == true) { return $this->redirect('list_category'); } else { $data['notification'] = 'Co loi xay ra'; } } return $this->render('admin/category/form.html.twig', $data); }
public function FormAction($idcate, $id = '') { // if ($id != '') { $data['action'] = 'update'; $action = 'Cập nhật'; $data['product'] = Model::getById('products', $id); } else { $data['action'] = 'add'; $action = 'Thêm mới'; } $data['title'] = $action . ' sản phẩm '; $data['fullname'] = $this->app['session']->get('admin', ''); // if ($input = $this->getPostData()) { $url = $this->app['slugify']->slugify($input['name']); $input = array('name' => $input['name'], 'images' => $input['images'], 'target' => $url, 'cate' => $idcate, 'made' => $input['made'], 'num' => $input['num'], 'price' => $input['price']); if ($data['action'] == 'add') { $product = Model::add('products', $input); } else { $product = Model::update('products', $input, $id); } if ($product == true) { return $this->redirect('list_Products', array('idcate' => $idcate)); } else { $data['notification'] = 'co loi xay ra'; } } return $this->render('admin/post/form.html.twig', $data); }