当前位置: 首页>>代码示例>>PHP>>正文


PHP Item::findOne方法代码示例

本文整理汇总了PHP中app\models\Item::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::findOne方法的具体用法?PHP Item::findOne怎么用?PHP Item::findOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Item的用法示例。


在下文中一共展示了Item::findOne方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findModel

 /**
  * Finds the Item model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Item the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Item::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
开发者ID:robby-xp,项目名称:IMS,代码行数:15,代码来源:ItemController.php

示例2: findModel

 /**
  * 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 findModel($id)
 {
     $model = Item::findOne($id);
     if ($model === null) {
         throw new \yii\web\HttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
开发者ID:chaimvaid,项目名称:linet3,代码行数:13,代码来源:ItemController.php

示例3: actionDelete

 /**
  * Deletes an existing Purchase model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $modelDetails = $model->getPurchasesDetails()->all();
     $transaction = \Yii::$app->db->beginTransaction();
     try {
         foreach ($modelDetails as $modelDetail) {
             $item = Item::findOne($modelDetail->item_id);
             $item->stock -= $modelDetail->quantity;
             if (!($flag = $item->save())) {
                 $transaction->rollBack();
                 break;
             }
         }
         if ($flag) {
             if ($model->delete()) {
                 $transaction->commit();
             } else {
                 $transaction->rollBack();
             }
         }
     } catch (Exception $e) {
         $transaction->rollBack();
     }
     return $this->redirect(['index']);
 }
开发者ID:robby-xp,项目名称:IMS,代码行数:32,代码来源:PurchaseController.php

示例4: itemVal

 public function itemVal($attribute, $params)
 {
     $item = Item::findOne(["id" => $this->{$attribute}]);
     if ($item === null) {
         $this->addError($attribute, Yii::t('app', 'Item id not found'));
     }
 }
开发者ID:chaimvaid,项目名称:linet3,代码行数:7,代码来源:Docdetails.php


注:本文中的app\models\Item::findOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。