I want to make a multiple category dropdown in product form yii2. The table category has a parent_id column. So when I want to choose the category with parent_id 0 or 1 it shows other categories with that parent_id. I use gii generator. Can you help me make controller model view it? controller
public function actionCreate()
{
$model = new Product();
$category = new Category();
$time = time();
$model->created_at = $time;
$model->updated_at = $time;
$dataCat = $category->getCategoryParent();
if(empty($dataCat)){
$dataCat = array();
}
view
<?= $form->field($model, 'category_id')->dropDownList($dataCat,['prompt'=>'--obat--']) ?>
model
public function getCategoryParent()
{
return $this->hasOne(Category::className(), ['idCate' => 'category_id']);
}