本文整理汇总了PHP中Products::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP Products::findFirst方法的具体用法?PHP Products::findFirst怎么用?PHP Products::findFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products
的用法示例。
在下文中一共展示了Products::findFirst方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: productAction
public function productAction($id)
{
if ($id) {
$product = Products::findFirst("id =" . $id);
$this->view->product = $product;
} else {
$this->response->redirect("/service/index");
}
}
示例2: updateAction
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"));
}
}
示例3: update
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();
}
}
示例4: deleteAction
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");
}
}
示例5: indexAction
public function indexAction()
{
$this->view->product = Products::findFirst();
}
示例6: indexAction
public function indexAction()
{
$this->view->setVar('product', Products::findFirst());
}
示例7: getProductAction
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();
}
}