wbraganca / yii2-dynamicform

It is widget to yii2 framework to clone form elements in a nested manner, maintaining accessibility.
Other
436 stars 438 forks source link

Unknown Property – yii\base\UnknownPropertyException Getting unknown property: app\models\PlanDetail::0 #143

Open jackhad opened 8 years ago

jackhad commented 8 years ago

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'

            ],
        ]); ?>`
yafater commented 8 years ago

What do you define $planDetailModels in your controller?

jackhad commented 8 years ago

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?

yafater commented 8 years ago

Please view this ,actionUpdate function, It's good sample for you.

jackhad commented 8 years ago

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?

yafater commented 8 years ago

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"

jackhad commented 8 years ago

Wow..Thanks @yafater now populating as Expected.

many thanks :+1:

isaygo commented 8 years ago
    public function actionUpdate($id)
    {
        $modelCustomer = $this->findModel($id);
        $modelsAddress = $modelCustomer->mac;

And i got Getting unknown property: common\models\Users::mac

cyakant commented 3 years ago

Thank you I have also apply this code and my problem was solved. $planDetailModels = [new PlanDetail(['plan_id' => $id])];