yii2-dynamicform
yii2-dynamicform copied to clipboard
Unknown Property – yii\base\UnknownPropertyException Getting unknown property: app\models\PlanDetail::0
I got this error
Unknown Property – yii\base\UnknownPropertyException
Getting unknown property: app\models\PlanDetail::0
while implementing this
` <?php
use wbraganca\dynamicform\DynamicFormWidget;
DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "" [A-Za-z0-9]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 4, // the maximum times, an element can be cloned (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $planDetailModels[0],
'formId' => 'dynamic-form',
'formFields' => [
'name',
'value',
'type'
],
]); ?>`
What do you define $planDetailModels in your controller?
ah..Thanks for your reply..I got the issue.
I have missed the array bracket while declaring at controller
$planDetailModels = [new PlanDetail()];
Along with this I have Question.How do we declare the same at Update()
I tried this
$model = $this->findModel($id); $planDetailModels = [new PlanDetail(['plan_id' => $id])];
but no data are populated in update form..Any idea pls?
Please view this ,actionUpdate function, It's good sample for you.
I dont understand still
$modelCustomer = $this->findModel($id); $modelsAddress = $modelCustomer->addresses;
in update what is $modelCustomer->addresses
??
in my design plan and plan_details are join tables plan_details table plan_id is the foreign key of plan table
So how should I declare in my update() function?
You have a relation function in your plan model, it has a name like getPlandetail or another thing so in your controller you should be declare your planDetailModels like this $planDetailModels=$model->Plandetail; Note that Plandetail is getPlandetail without "get"
Wow..Thanks @yafater now populating as Expected.
many thanks :+1:
public function actionUpdate($id)
{
$modelCustomer = $this->findModel($id);
$modelsAddress = $modelCustomer->mac;
And i got Getting unknown property: common\models\Users::mac
Thank you I have also apply this code and my problem was solved. $planDetailModels = [new PlanDetail(['plan_id' => $id])];