0
votes

I am trying to insert an item into my database using Yii, but I am getting the following error:

Unknown Property – yii\base\UnknownPropertyException

Getting unknown property: app\models\Item::lock

in .../_protected/vendor/yiisoft/yii2/base/Component.php

I am a complete beginner in Yii and PHP, so I don't even know where to look. I have tried finding something similar online, and found that the potential cause could be the case-sensitivity: my model class is called Item, and my table is called item (phpMyAdmin changed the name to lowercase), but I still have no idea what to do.

Edit:

This is my Item model:

class Item extends BaseItem
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return array_replace_recursive(parent::rules(),
        [
            [['InventoryNumber', 'ItemStatus', 'ItemType', 'ItemName', 'PurchaseDate', 'PurchaseValue', 'Amortization', 'LocationId', 'PersonId'], 'required'],
            [['InventoryNumber', 'LocationId', 'PersonId'], 'integer'],
            [['PurchaseDate'], 'safe'],
            [['PurchaseValue', 'Amortization'], 'number'],
            [['ItemStatus'], 'string', 'max' => 20],
            [['ItemType'], 'string', 'max' => 30],
            [['ItemName'], 'string', 'max' => 100],
            [['InventoryNumber'], 'unique'],
            [['lock'], 'default', 'value' => '0'],
            [['lock'], 'mootensai\components\OptimisticLockValidator']
        ]);
    }   
}

The lock fields are automatically generated, I haven't added them into my database.

1
Does your database table has lock field?Paul
@paul No, it doesn't, that was automatically generated.Eutherpy
Then you might declare lock as safe. [['PurchaseDate', 'lock'], 'safe'],Paul

1 Answers

2
votes

Add declaration to your class

class Item extends BaseItem
{
    public $lock;
.....
}