<tr> <td> <?php echo Html::encode($widget_applying->part->name); ?> </td> <td> <?php echo Html::a(Icon::show('trash-o') . ' ' . Yii::t('app', 'Remove'), ['remove-applying', 'part_id' => $widget_applying->part->id, 'id' => $model->id], ['class' => 'btn btn-xs btn-danger']); ?> </td> </tr> <?php } ?> </tbody> </table> </fieldset> <?php echo Html::dropDownList('new-part', null, [0 => Yii::t('app', 'Select theme part to add')] + \yii\helpers\ArrayHelper::map(\app\extensions\DefaultTheme\models\ThemeParts::getAllParts(), 'id', 'name'), ['class' => 'new-part-select']); ?> <?php BackendWidget::end(); ?> </article> </div> </section> <?php ActiveForm::end();
public function actionActiveWidgets($id) { $variation = $this->loadModel(ThemeVariation::className(), $id); if (isset($_POST['addWidget'], $_POST['partId'])) { $part = ThemeParts::findById($_POST['partId']); if ($part === null) { throw new NotFoundHttpException(); } $widget = ThemeWidgets::findById($_POST['addWidget']); if ($widget === null) { throw new NotFoundHttpException(); } $binding = new ThemeActiveWidgets(); $binding->part_id = $part->id; $binding->variation_id = $variation->id; $binding->widget_id = $widget->id; $binding->save(); } $models = ThemeActiveWidgets::find()->where(['variation_id' => $variation->id])->orderBy(['part_id' => SORT_ASC, 'sort_order' => SORT_ASC])->all(); // Warning! Element of $allParts is not a model! It's an array of db rows $allParts = ThemeParts::getAllParts(); $availableWidgets = ThemeWidgets::find()->joinWith('applying')->all(); return $this->render('active-widgets', ['variation' => $variation, 'models' => $models, 'availableWidgets' => $availableWidgets, 'allParts' => $allParts]); }