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);
 }
 public function registerAction()
 {
     $data['null'] = '';
     if ($this->getPostData('register')) {
         $input = $this->getPostData();
         if (Model::issetUser('user', $input['user'])) {
             $data['notification'] = 'User đã tồn tại';
             return $this->render('default/home/login.html.twig', $data);
         } else {
             $input = array('username' => $input['user'], 'email' => $input['email'], 'password' => md5($input['password']));
             if (Model::add('user', $input)) {
                 return $this->redirect('index');
             } else {
                 $data['notification'] = 'Có lỗi xảy ra';
                 return $this->render('default/home/login.html.twig', $data);
             }
         }
     }
     return $this->render('default/home/login.html.twig', $data);
 }