本文整理汇总了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>
示例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);
}
示例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')]]);