Hi all,
I currently have a working DDM(drop down menu) in a view utilizing an actionCreate in a controller that produces a new Product record. I’m trying to use this as an example to create a DDM for the view; however, I really don’t understand how the variable $model (view file) creating the DDM is defined. It seems to me it is defined in the controller like so:
public function actionCreate()
{
$model = new Products();
if ($model->load(Yii::$app->request->post()))
{
$imageName = $model->product_name;
$model->file = UploadedFile::getInstance($model,'file');
$model->image_name = $imageName.'.'.$model->file->extension;
$model->save();
$model->file->saveAs( '../../../uploads_grider2/'.$imageName.'.'.$model->file->extension );
return $this->redirect(['view', 'id' => $model->product_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
<?= $form->field($model, 'brand_id', [
'horizontalCssClasses' => [
'wrapper' => 'col-sm-3',
]])->dropDownList($dataBrandName,
['prompt'=>' ----- Choose a Brand -----']) ?>
I’m trying to utilize this DDM with an actionCreate as an example to customize for the purpose of viewing products by brand with a DDM. When I copy the actionCreate to the SiteController is says that model is not defined. Obviously I do not need actionCreate for the purpose of viewing; however I get the same error message when trying to utilize actionView & actionIndex. So I thought I would start my questions centered around the understanding as to why $model is properly defined in a ProductsController and not in the SiteController. Thanks in advance for you time and consideration.