I do sub categories on yii if necessary I add sub categories if there is no then an empty field (I create the first category and then this category appears)
Category names choose a category from the drop-down list status (published a draft)
DB structure category_id category_name
parent_id
category_status
<?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'category_name')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'parent_id')->dropDownList(ArrayHelper::map(Category::find()->all(), 'category_id', 'category_name')) ?> <?= $form->field($model, 'category_status')->dropDownList(['0' => 'Черновик', '1' => 'Опубликован']) ?> <div class="form-group"> <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> </div> <?php ActiveForm::end(); ?> How to make it so that when you click on a category selection, an empty field falls out first.
<?= $form->field($model, 'parent_id')->dropDownList(ArrayHelper::map(Category::find()->all(), 'category_id', 'category_name'), ['prompt'=>' ']) ?>-