本文整理汇总了PHP中Products::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Products::find方法的具体用法?PHP Products::find怎么用?PHP Products::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products
的用法示例。
在下文中一共展示了Products::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: searchAction
public function searchAction()
{
$numberPage = 1;
if ($this->request->isPost()) {
$query = Phalcon_Model_Query::fromInput("Products", $_POST);
$this->session->conditions = $query->getConditions();
} else {
$numberPage = $this->request->getQuery("page", "int");
if ($numberPage <= 0) {
$numberPage = 1;
}
}
$parameters = array();
if ($this->session->conditions) {
$parameters["conditions"] = $this->session->conditions;
}
$parameters["order"] = "id";
$products = Products::find($parameters);
if (count($products) == 0) {
Flash::notice("The search did not find any products", "alert alert-info");
return $this->_forward("products/index");
}
$paginator = Phalcon_Paginator::factory("Model", array("data" => $products, "limit" => 5, "page" => $numberPage));
$page = $paginator->getPaginate();
$this->view->setVar("page", $page);
$this->view->setVar("products", $products);
}
示例2: searchAction
public function searchAction()
{
$numberPage = 1;
if ($this->request->isPost()) {
$query = Criteria::fromInput($this->di, "Products", $_POST);
$this->persistent->searchParams = $query->getParams();
} else {
$numberPage = $this->request->getQuery("page", "int");
if ($numberPage <= 0) {
$numberPage = 1;
}
}
$parameters = array();
if ($this->persistent->searchParams) {
$parameters = $this->persistent->searchParams;
}
$products = Products::find($parameters);
if (count($products) == 0) {
$this->flash->notice("The search did not find any products");
return $this->forward("products/index");
}
$paginator = new Phalcon\Paginator\Adapter\Model(array("data" => $products, "limit" => 5, "page" => $numberPage));
$page = $paginator->getPaginate();
$this->view->setVar("page", $page);
}
示例3: deleteAction
/**
* Delete a customer record
*/
public function deleteAction()
{
$productsTable = new Products();
$product = $productsTable->find($this->_getParam('id'))->current();
!is_null($product) && $product->delete();
$this->_redirect('/products');
}
示例4: updateStock
public static function updateStock($productId)
{
$product = Products::find($productId);
$stockQuantity = Stocks::whereProductId($productId)->sum('quantity');
$soldQuantity = SalesItems::where('product_id', '=', $productId)->sum('quantity');
$product->quantity = $stockQuantity - $soldQuantity;
$product->save();
}
示例5: indexAction
public function indexAction()
{
$indexProducts = Products::find(array("limit" => 5, "order" => "id asc"));
$products = Products::find(array("order" => "id asc"));
$paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $products, "limit" => 8, "page" => $dynamicPageBegin));
$this->view->page = $paginator->getPaginate();
$this->view->indexProducts = $indexProducts;
}
示例6: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$discountTypes = ['' => 'Select Discount Type', 'percentage' => 'Percentage', 'fixed' => 'Fixed'];
$statuses = Discounts::$statuses;
$discount = Discounts::find($id);
$product = Products::find($discount->product_id);
return View::make('discounts.edit', compact('discountTypes', 'product', 'statuses', 'discount'));
}
示例7: indexAction
public function indexAction()
{
$currentPage = 1;
$currentPage = $this->request->get("page");
$products = Products::find();
$paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $products, "limit" => 4, "page" => $currentPage));
$page = $paginator->getPaginate();
$this->view->setVar("page", $page);
}
示例8: findProductCoalesced
/**
* @param int $customerId
* @param int $productId
*/
public function findProductCoalesced($customerId, $productId)
{
$productsTable = new Products();
$p = $productsTable->find($productId)->current();
$cp = $this->find($productId, $customerId)->current();
if ($cp) {
$productCoalesced = array('product_id' => $cp->product_id, 'sku' => $cp->sku ?: $p->sku, 'name' => $cp->name ?: $p->name, 'description' => $cp->description ?: $p->description, 'unit_price' => $cp->unit_price ?: $p->unit_price);
} else {
$productCoalesced = array('product_id' => $p->product_id, 'sku' => $p->sku, 'name' => $p->name, 'description' => $p->description, 'unit_price' => $p->unit_price);
}
return $productCoalesced;
}
示例9: indexAction
public function indexAction()
{
$news1 = News::find(array("typeid = 1", "order" => "inputtime desc", "limit" => 5));
$news2 = News::find(array("typeid = 2", "order" => "inputtime desc", "limit" => 5));
$news3 = News::find(array("typeid = 3", "order" => "inputtime desc", "limit" => 3));
$news4 = News::find(array("typeid = 4", "order" => "inputtime desc", "limit" => 5));
$indexProducts = Products::find(array("limit" => 5, "order" => "id asc"));
$this->view->indexProducts = $indexProducts;
$this->view->setVar("news1", $news1);
$this->view->setVar("news2", $news2);
$this->view->setVar("news3", $news3);
$this->view->setVar("news4", $news4);
}
示例10: findByName
public static function findByName($name)
{
$response = new Response();
if (!$name) {
$response->status = $response::STATUS_BAD_REQUEST;
$response->addError('NAME_IS_REQUIRED');
return $response->toArray();
}
try {
$response->data = Products::find(['conditions' => 'name LIKE :name:', 'bind' => ['name' => '%' . $name . '%'], 'order' => 'name DESC'])->toArray();
} catch (Exception $e) {
$response->setException($e);
} finally {
return $response->toArray();
}
}
示例11: array
<?php
// Using data from a resultset
echo $this->tag->select(array("productId", Products::find("type = 'vegetables'"), "using" => array("id", "name")));
// Using data from an array
echo $this->tag->selectStatic(array("status", array("A" => "Active", "I" => "Inactive")));
示例12: array
<?php
//Passing a resultset as data
$paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => Products::find(), "limit" => 10, "page" => $currentPage));
//Passing an array as data
$paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => array(array('id' => 1, 'name' => 'Artichoke'), array('id' => 2, 'name' => 'Carrots'), array('id' => 3, 'name' => 'Beet'), array('id' => 4, 'name' => 'Lettuce'), array('id' => 5, 'name' => '')), "limit" => 2, "page" => $currentPage));
//Passing a querybuilder as data
$builder = $this->modelsManager->createBuilder()->columns('id, name')->from('Robots')->orderBy('name');
$paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 20, "page" => 1));
示例13: initialize
{
// fields
public $id;
public $name;
public function initialize()
{
// $this->setSource("the_robots");
}
}
// Find record with id = 3
$robot = Robots::findFirst(3);
// *** paginator ***
use Phalcon\Paginator\Adapter\Model as ModelPaginator;
use Phalcon\Paginator\Adapter\NativeArray as ArrayPaginator;
use Phalcon\Paginator\Adapter\QueryBuilder as BuildPaginator;
//Passing a resultset as data
$paginator = new ModelPaginator(array("data" => Products::find(), "limit" => 10, "page" => $currentPage));
//Passing an array as data
$paginator = new ArrayPaginator(array("data" => array(array('id' => 1, 'name' => 'Artichoke'), array('id' => 2, 'name' => 'Carrots'), array('id' => 3, 'name' => 'Beet'), array('id' => 4, 'name' => 'Lettuce'), array('id' => 5, 'name' => '')), "limit" => 2, "page" => $currentPage));
$builder = $this->modelsManager->createBuilder()->from("App\\Models\\Article")->where($where)->orderBy("create_time DESC");
$paginator = new BuildPaginator(array("builder" => $builder, "limit" => 5, "page" => $this->request->queryPage()));
$dataset = $paginator->getPaginate();
/*
items The set of records to be displayed at the current page
current The current page
before The previous page to the current one
next The next page to the current one
last The last page in the set of records
total_pages The number of pages
total_items The number of items in the source data
//*/
示例14:
<?php
$products = Products::find($parameters);
if (count($products) == 0) {
$this->flash->notice("The search did not found any products");
return $this->forward("products/index");
}
示例15: returnitem
public function returnitem($id)
{
$sales = SalesItems::where('sales_id', '=', $id)->get();
if ($sales) {
foreach ($sales as $sale) {
if ($this->user->outlet_id != 0) {
$outletstock = OutletsStocks::where('product_id', '=', $sale->product_id)->where('outlet_id', '=', $this->user->outlet_id)->first();
if ($outletstock) {
$outletstock->quantity = $outletstock->quantity + $sale->quantity;
$outletstock->save();
SalesItems::destroy($sale->id);
}
} else {
$product = Products::find($sale->product_id);
if ($product) {
// var_dump($product);exit();
$product->quantity = $product->quantity + $sale->quantity;
$product->save();
SalesItems::destroy($sale->id);
}
}
}
Sales::destroy($id);
return Redirect::route('sales.index')->with('success', 'Item successfully return');
}
}