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 AddCartAction() { $user = $this->app['session']->get('user', ''); $shopcart = $this->app['session']->get('cart_' . $user, ''); if ($shopcart == '') { $shopcart = array(); } $iss = ''; if ($input = $this->getPostData()) { $total_price = $input['total_price']; for ($i = 0; $i < count($shopcart); $i++) { if ($input['id_'] == $shopcart[$i]['id']) { $shopcart[$i]['quantity']++; $shopcart[$i]['total'] = $shopcart[$i]['quantity'] * $shopcart[$i]['price']; $shopcart[$i]['total_price'] = $total_price = $shopcart[$i]['total_price'] + $shopcart[$i]['price']; $iss = true; } else { $shopcart[$i]['total_price'] = $total_price = $total_price + $shopcart[$i]['total']; } } if ($iss == '') { $pro = Model::getById('products', $input['id_']); $total_price = $total_price + $pro->price; $cart = array('id' => $pro->id, 'images' => $pro->images, 'price' => $pro->price, 'total' => $pro->price, 'name' => $pro->name, 'num' => $pro->num, 'quantity' => 1, 'total_price' => $total_price); array_push($shopcart, $cart); } $data['total_price'] = $total_price; $this->app['session']->set('cart_' . $user, $shopcart); echo $pro['id']; exit; } }
public function indexAction() { $data['products'] = Model::getAll('products'); $data['cate'] = Model::getAll('cate'); $data['user'] = $this->app['session']->get('user', ''); return $this->render('default/home/home.html.twig', $data); }
public function DeleteAction($idcate, $id) { $data['title'] = 'Xóa Tin Tức'; $data['fullname'] = $this->app['session']->get('adminName', '1'); $cate = Model::delete('products', $id); if ($cate == false) { $this->app['session']->getFlashBag()->add('message', 'không thành công'); } return $this->redirect('list_Products', array('idcate' => $idcate)); }
public function LoginAction() { $data['title'] = 'Đăng nhập vào hệ thống'; $data['notification'] = 'Đăng nhập vào hệ thống'; if ($input = $this->getPostData()) { $user = Model::CheckUserAdmin('user', $input['username'], $input['password']); if ($user) { $this->app['session']->set('admin', $input['username']); return $this->redirect('admin-home'); } else { $data['notification'] = 'Username hoặc password không đúng'; } } return $this->render('admin/auth/login.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); }