Teskuroi
Новичок
Метод контроллера:
Естественно $good_attachment_types_id в безымянной функции равен NULL. Ума не приложу как сделать так, чтобы добиться нужного функционала. Подскажите, пожалуйста.
PHP:
global $good_attachment_types_id;
$good_id = Yii::$app->request->get()['id'];
$attachmentTypes = AttachmentType::findAll([
'is_public' => AttachmentType::IS_PUBLIC,
'model' => AttachmentType::MODEL_CATALOG_GOOD
]);
$good_attachment_types_id = $category_attachment_types_id = [];
foreach ($attachmentTypes as $attachmentType) {
$good_attachment_types_id[] = $attachmentType->id;
}
$attributes = CatalogGoodAttributeType::find()->all();
/** @var CatalogGood $good */
$good = CatalogGood::find()->where([
'id' => $good_id,
'is_deleted' => CatalogGood::STATUS_NOT_DELETED
])->with([
'childrenGoods.attachments' => function ($query) {
global $good_attachment_types_id;
/** @var $query ActiveQuery */
$query->andWhere(['attachment_type_id' => $good_attachment_types_id]);
},
'childrenGoods.textures',
'childrenGoods.activeDiscount',
'compositions.marks',
'attachments' => function ($query) {
global $good_attachment_types_id;
/** @var $query ActiveQuery */
$query->andWhere(['attachment_type_id' => $good_attachment_types_id]);
},
'textures',
'activeDiscount',
'goodAttributes'
])->one();
return $this->render('meta-good', [
'attachmentTypes' => $attachmentTypes,
'attributes' => $attributes,
'good' => $good
]);