本文整理汇总了PHP中app\modules\shop\models\Product::findAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::findAll方法的具体用法?PHP Product::findAll怎么用?PHP Product::findAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\modules\shop\models\Product
的用法示例。
在下文中一共展示了Product::findAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
* @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\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 = Product::findAll($productIds);
?>
<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: beforeDelete
/**
* Preparation to delete category.
* Deleting related products and inserted categories.
* @return bool
*/
public function beforeDelete()
{
if (!parent::beforeDelete()) {
return false;
}
$productObject = Object::getForClass(Product::className());
switch ($this->deleteMode) {
case self::DELETE_MODE_ALL:
$products = !is_null($productObject) ? Product::find()->join('INNER JOIN', $productObject->categories_table_name . ' pc', 'pc.object_model_id = product.id')->where('pc.category_id = :id', [':id' => $this->id])->all() : [];
break;
case self::DELETE_MODE_MAIN_CATEGORY:
$products = Product::findAll(['main_category_id' => $this->id]);
break;
default:
$products = !is_null($productObject) ? Product::find()->join('INNER JOIN', $productObject->categories_table_name . ' pc', 'pc.object_model_id = product.id')->join('INNER JOIN', $productObject->categories_table_name . ' pc2', 'pc2.object_model_id = product.id')->where('pc.category_id = :id', [':id' => $this->id])->groupBy('pc2.object_model_id')->having('COUNT(*) = 1')->all() : [];
break;
}
foreach ($products as $product) {
$product->delete();
}
foreach ($this->children as $child) {
$child->deleteMode = $this->deleteMode;
$child->delete();
}
if (!is_null($productObject)) {
Yii::$app->db->createCommand()->delete($productObject->categories_table_name, ['category_id' => $this->id])->execute();
}
return true;
}
示例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 = ArrayHelper::map(Product::findAll($productIds), 'id', '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')]]);