Good afternoon.
I made a combo which shows the respective data of an option, but this is only loaded when navigating in the other options and returning to the first option.
I need help to show the combo data when the page is reloaded for the first time without having to click on the other options.
For your help, thanks.
Attached code.
Combo Code
$cat = ArrayHelper::map(Category::find()->all(), ‘id’, ‘name_category’);
echo $form->field($model, ‘category_id’)->dropDownList(
$cat,
[
‘prompt’=>‘All the products’,
‘onchange’=>‘javascript:this.form.submit();’,
]
);
?>
Name | Description | Price |
---|
Combo function
public function actionCategoryProduct()
{
$model = new Product();
if ($model->load(Yii::$app->request->post()) && empty($model->category_id)) {
$pt = Product::findBySql("SELECT * FROM product")->all();
return $this->render('category-product', ['model' => $model, 'pt' => $pt]);
}elseif ($model->load(Yii::$app->request->post()) ) {
$produc = Product::findBySql("SELECT * FROM product WHERE category_id = ".$model->categoria_id."")
->all();
return $this->render('category-product', ['model' => $model, 'produc' => $produc]);
}
return $this->render('category-product', ['model' => $model]);
}