當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Product::findOne方法代碼示例

本文整理匯總了PHP中app\modules\shop\models\Product::findOne方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::findOne方法的具體用法?PHP Product::findOne怎麽用?PHP Product::findOne使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\modules\shop\models\Product的用法示例。


在下文中一共展示了Product::findOne方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1:

 * @var $model \app\properties\AbstractModel
 * @var $multiple boolean
 * @var $property_id integer
 * @var $property_key string
 * @var $this \yii\web\View
 * @var $values \app\properties\PropertyValue
 */
use app\models\Property;
use app\modules\shop\models\Product;
use yii\helpers\ArrayHelper;
use kartik\helpers\Html;
$productIds = ArrayHelper::getColumn($values->values, 'value');
/** @var Product[] $products */
$products = [];
foreach ($productIds as $id) {
    $products[] = Product::findOne($id);
}
?>

<dl>
    <?php 
if (count($productIds) == 0) {
    return;
}
$property = Property::findById($property_id);
echo Html::tag('dt', $property->name);
foreach ($products as $product) {
    echo Html::tag('dd', Html::a($product->name, ['@product', 'model' => $product]));
}
?>
</dl>
開發者ID:tqsq2005,項目名稱:dotplant2,代碼行數:31,代碼來源:frontend-render.php

示例2: actionDelete

 /**
  * @param $id
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  * @throws \Exception
  */
 public function actionDelete($id)
 {
     /** @var Product $model */
     if (null === ($model = Product::findOne($id))) {
         throw new NotFoundHttpException();
     }
     if (Yii::$app->request->get('returnUrl') !== null) {
         $redirect = Yii::$app->request->get('returnUrl');
     } elseif ($model->parent_id == 0) {
         $redirect = Url::toRoute(['index']);
     } else {
         $redirect = Url::toRoute(['edit', 'id' => $model->parent_id]);
     }
     if (!$model->delete()) {
         Yii::$app->session->setFlash('info', Yii::t('app', 'The object is placed in the cart'));
     } else {
         Yii::$app->session->setFlash('info', Yii::t('app', 'Object has been removed'));
     }
     return $this->redirect($redirect);
 }
開發者ID:pramana08,項目名稱:dotplant2,代碼行數:26,代碼來源:BackendProductController.php

示例3:

<?php

/**
 * @var $attribute_name string
 * @var $form \yii\widgets\ActiveForm
 * @var $label string
 * @var $model \app\properties\AbstractModel
 * @var $multiple boolean
 * @var $property_id integer
 * @var $property_key string
 * @var $this \yii\web\View
 * @var $values \app\properties\PropertyValue
 */
use app\modules\shop\models\Product;
use yii\helpers\ArrayHelper;
$productIds = ArrayHelper::getColumn($values->values, 'value');
$data = [];
foreach ($values->values as $value) {
    $product = Product::findOne($value['value']);
    if (is_object($product)) {
        $data[$product->id] = $product->name;
    }
}
?>

<?php 
echo \app\backend\widgets\Select2Ajax::widget(['initialData' => $data, 'form' => $form, 'model' => $model, 'modelAttribute' => $property_key, 'multiple' => $multiple === 1, 'searchUrl' => '/shop/backend-product/ajax-related-product', 'additional' => ['placeholder' => Yii::t('app', 'Search')]]);
開發者ID:tqsq2005,項目名稱:dotplant2,代碼行數:27,代碼來源:frontend-edit.php


注:本文中的app\modules\shop\models\Product::findOne方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。