public function productAction($id) { if ($id) { $product = Products::findFirst("id =" . $id); $this->view->product = $product; } else { $this->response->redirect("/service/index"); } }
public function updateAction() { $this->view->disable(); $product = Products::findFirst($this->request->getPost("id")); $product->category_id = intval($this->request->getPost("category_id")); $product->status = $this->request->getPost("status"); if ($product->save()) { echo json_encode(array("status" => "OK")); } else { echo json_encode(array("status" => "NG")); } }
public static function update($id, $data) { $response = new Response(); try { $data = json_decode($data, true); $category = Categories::findFirst($data->categoryId); if ($category !== FALSE) { /** @var Products $products */ $product = Products::findFirst($id); $product->setAttributes($data); $response->data = $product->update(); } else { $response->status = $response::STATUS_BAD_REQUEST; $response->addError('CATEGORIES_NOT_FOUND'); } } catch (Exception $e) { $response->setException($e); } finally { return $response->toArray(); } }
public function deleteAction($id) { $id = $this->filter->sanitize($id, array("int")); $products = Products::findFirst('id="' . $id . '"'); if (!$products) { $this->flash->error("Product was not found"); return $this->forward("products/index"); } if (!$products->delete()) { foreach ($products->getMessages() as $message) { $this->flash->error((string) $message); } return $this->forward("products/search"); } else { $this->flash->success("Products was deleted"); return $this->forward("products/index"); } }
public function indexAction() { $this->view->product = Products::findFirst(); }
public function indexAction() { $this->view->setVar('product', Products::findFirst()); }
public function getProductAction() { if (ApiController::access()) { if (isset($_POST['id'])) { $product = Products::findFirst($this->request->getPost('id')); } else { $product = Products::find(); } if ($product != false) { foreach ($product as $row) { $response[$row->name]['name'] = $row->name; $response[$row->name]['category'] = $row->category; $response[$row->name]['description'] = $row->description; } echo json_encode($response); } $this->view->disable(); } }