本文整理汇总了PHP中Item::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::model方法的具体用法?PHP Item::model怎么用?PHP Item::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Item
的用法示例。
在下文中一共展示了Item::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionAdditem
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionAdditem($item_id)
{
$user_id = Yii::app()->user->id;
// find the users cart
$user = User::model()->find(array('condition' => 'id=:user_id', 'params' => array(':user_id' => $user_id)));
// find the users cart
$cart = Cart::model()->find(array('condition' => 'cart_owner=:cart_owner', 'params' => array(':cart_owner' => $user_id)));
// find the item being reffered to by item_id
$item = Item::model()->find(array('condition' => 'id=:item_id', 'params' => array(':item_id' => $item_id)));
if (is_null($cart)) {
// if the cart is not found. create a cart for the user.
$cart = new Cart();
$cart->cart_owner = $user->id;
$cart->save();
}
// check if the same order was already made & increment else, create new
$order = Order::model()->find(array('condition' => 'item_id=:item_id AND cart_id=:cart_id AND order_by=:order_by', 'params' => array(':item_id' => $item_id, ':cart_id' => $cart->id, ':order_by' => $user->id)));
if (is_null($order)) {
$order = new Order();
$order->create_time = time();
$order->quantity = 1;
$order->item_id = $item->id;
$order->cart_id = $cart->id;
$order->order_by = $user->id;
} else {
$order->quantity = 1 + $order->quantity;
$order->update_time = time();
}
$order->save();
// find all orders by this user.
$orders = Order::model()->findAll('cart_id=:cart_id AND order_by=:order_by', array(':cart_id' => $cart->id, ':order_by' => $user->id));
$return = array('success' => true, 'data' => $orders);
echo CJavaScript::jsonEncode($return);
Yii::app()->end();
}
示例2: run
public function run($id)
{
$item_info = Item::model()->findByPk($id);
if ($item_info->delete()) {
$this->controller->success('');
}
}
示例3: actionIndex
public function actionIndex($key)
{
$category = Category::model()->findByPk(3);
$model = $category->findByAttributes(array('url' => $key));
if ($model) {
$childs = $model->descendants()->findAll();
$ids = array($model->id);
foreach ($childs as $child) {
$ids[] = $child->id;
}
$cid = implode(',', $ids);
$criteria = new CDbCriteria(array('condition' => 'category_id in ( ' . $cid . ')', 'order' => 'item_id desc, sort_order desc'));
$count = Item::model()->count($criteria);
$pages = new CPagination($count);
// results per page
$pages->pageSize = 20;
$pages->applyLimit($criteria);
$items = Item::model()->findAll($criteria);
// $items = new CActiveDataProvider('Item', array(
// 'criteria' => $criteria
// ));
$criteria = new CDbCriteria(array('condition' => 'is_hot = 1 and category_id in ( ' . $cid . ')', 'limit' => '4', 'order' => 'item_id desc, sort_order desc'));
$hotItems = Item::model()->findAll($criteria);
$this->render('index', array('model' => $model, 'items' => $items, 'pages' => $pages, 'hotItems' => $hotItems, 'key' => $key));
} else {
$this->render('index');
}
}
示例4: actionIndex
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$cri = new CDbCriteria(array('condition' => 'is_show = 1 and is_best = 1'));
$best_items = Item::model()->findAll($cri);
$this->render('index', array('best_items' => $best_items));
}
示例5: loadItemsModel
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadItemsModel($criteria)
{
$items = Item::model()->findAll($criteria);
if ($items === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $items;
}
示例6: loadModel
{
unset(Yii::app()->request->cookies['history']);
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
示例7: getItems
{
parent::init();
}
public function getItems()
{
if (isset(Yii::app()->request->cookies['history'])) {
$ids = Yii::app()->request->cookies['history']->value;
$item_ids = explode(',', $ids);
foreach ($item_ids as $item_id) {
$items[] = Item::model()->findByPk($item_id);
}
示例8: run
public function run()
{
$id = Yii::app()->request->getParam('id', 0);
$item_model = Item::model()->findByPk($id);
if (isset($_POST['Item'])) {
$item_model->attributes = $_POST['Item'];
if ($item_model->save()) {
$this->controller->redirect("/mama/item/index/");
}
}
$this->controller->render('update', array('item_model' => $item_model));
}
示例9: getCategory
public static function getCategory($category)
{
$criteria = new CDbCriteria();
$criteria->select = $category;
// only select the 'title' column
$criteria->distinct = true;
$rs = Item::model()->findAll($criteria);
// $params is not needed
foreach ($rs as $row) {
$retVal[]["value"] = $row[$category];
}
return $retVal;
}
示例10: ini
private function ini()
{
if (!$this->ini) {
$this->_precision = Yii::app()->user->getSetting('company.precision');
$this->iVatRate = Item::model()->findByPK($this->item_id)->vat;
$this->rate = Currates::model()->GetRate($this->currency_id);
if ($this->doc_rate == 0) {
$doc = Docs::model()->findByPk($this->doc_id);
$this->doc_rate = Currates::model()->GetRate($doc->currency_id);
}
$this->ini != $this->ini;
}
}
示例11: actionShow
public function actionShow($id)
{
$model = Item::model()->published()->with(array('producer', 'categories' => array('scopes' => 'published', 'order' => 'categories.sort ASC'), 'reasons' => array('scopes' => 'active', 'order' => 'reasons.sort ASC'), 'products' => array('scopes' => 'active', 'order' => 'products.sort ASC'), 'images' => array('scopes' => 'published', 'order' => 'images.sort ASC')))->findByPk($id);
if (!$model) {
throw new CHttpException(404);
}
// Учитываем фильтр в каталоге
$filter = Yii::app()->user->getState('chemicalCatalogFilter');
// Определяем следующий товар
$nextProduct = $model->getNextProduct($filter);
// Определяем предыдущий товар
$prevProduct = $model->getPrevProduct($filter);
$this->render('item', array('model' => $model, 'nextProduct' => $nextProduct, 'prevProduct' => $prevProduct, 'returnUrl' => Yii::app()->user->getState('stoneCatalogReturnUrl')));
}
示例12: actionIndex
public function actionIndex($key)
{
$model = Category::model()->findByAttributes(array('url' => $key));
$ids = $model->getMeChildsId($model->category_id);
$cid = implode(',', $ids);
$criteria = new CDbCriteria(array('condition' => 'category_id in ( ' . $cid . ')'));
$count = Item::model()->count($criteria);
$pages = new CPagination($count);
// results per page
$pages->pageSize = 20;
$pages->applyLimit($criteria);
$items = Item::model()->findAll($criteria);
$criteria = new CDbCriteria(array('condition' => 'is_hot = 1 and category_id in ( ' . $cid . ')', 'limit' => '4'));
$hotItems = Item::model()->findAll($criteria);
$this->render('index', array('model' => $model, 'items' => $items, 'pages' => $pages, 'hotItems' => $hotItems));
}
示例13: checkoutAction
function checkoutAction($params)
{
if ($this->isGuest()) {
$this->redirect("Site", "login");
}
$userId = $this->signedInUser()->id;
$itemId = $params["itemId"];
$item = Item::model()->find($itemId);
$item->quantity--;
$transaction = new Transaction();
$transaction->userId = $userId;
$transaction->itemId = $item->id;
$transaction->date = date("Y-m-d H:i:s");
$item->save();
$transaction->save();
$this->addFlash("Item bought successfully!");
return $this->redirect("Site", "index");
}
示例14: actionTestManyToMany
public function actionTestManyToMany()
{
$items = Item::model()->findAll();
$ingredients = Ingredient::model()->findAll();
foreach ($items as $item) {
echo $item->name . " has " . count($item->ingredients) . " ingredients. They are:<br />";
foreach ($item->ingredients as $ingredient) {
echo $ingredient->name . "<br />";
}
echo "<br />";
}
echo "<hr />";
foreach ($ingredients as $ingredient) {
echo $ingredient->name . " is associated with " . count($ingredient->items) . " items. They are:<br />";
foreach ($ingredient->items as $item) {
echo $item->name . "<br />";
}
echo "<br />";
}
}
示例15: addCart
public static function addCart($items, $item_id, $quantity, $discount, $price_tier, $price, $cost_price, $unit_price, $description, $expire_date)
{
$models = Item::model()->getItemPriceTierWS($item_id, $price_tier);
if (empty($models)) {
$models = Item::model()->getItemPriceTierItemNumWS($item_id, $price_tier);
foreach ($models as $model) {
$item_id = $model["id"];
}
}
if (!$models) {
return false;
}
foreach ($models as $model) {
$item_data = array((int) $item_id => array('item_id' => $model["id"], 'currency_code' => $model["currency_code"], 'currency_id' => $model["currency_id"], 'currency_symbol' => $model["currency_symbol"], 'name' => $model["name"], 'item_number' => $model["item_number"], 'quantity' => $quantity, 'cost_price' => $cost_price != null ? round($cost_price, Common::getDecimalPlace()) : round($model->cost_price, Common::getDecimalPlace()), 'unit_price' => $unit_price != null ? round($unit_price, Common::getDecimalPlace()) : round($model->unit_price, Common::getDecimalPlace()), 'price' => $price != null ? round($price, Common::getDecimalPlace()) : round($model["price"], Common::getDecimalPlace()), 'to_val' => 1, 'discount' => $discount, 'expire_date' => $expire_date, 'description' => $description != null ? $description : $model["description"]));
}
if (isset($items[$item_id])) {
$items[$item_id]['quantity'] += $quantity;
} else {
$items += $item_data;
}
return $items;
}