Setting unknown property: yii\validators\NumberValidator::0

megadruck

I try to call a setting form, which shows input forms for saving data into price database.

My model throws the above Exception during rendering:

Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: yii\validators\NumberValidator::0

error in line of _price-item:

$form->field($model, "[{$i}]credits")->textInput(['maxlength' => 8])

Model:

<?php

namespace app\models;


use Yii;

/**
 * @package app\models
 *
 * @property integer $id
 * @property integer $credits
 * @property integer $price
 * @property integer $reduced_price
 * @property integer $discount
 * @property string $start
 * @property string $end
 * @property integer $active

 */
class Price extends \app\base\ActiveRecord
{
    public function rules()
        {
            return [
                [['credits'], 'integer', 'required'],
                [['price'], 'integer','integerOnly' => false,'required', 'min' => 0, 'max' => 10000],
                [['reduced_price','discount'],'integer','integerOnly' => false,'min' => 0, 'max' => 10000],
                [['start','end'],'format' => 'php:Y-m-d H:i:s'],
                [['active'], 'integer'],
                [['active'], 'in', 'range' => array_keys(self::$_CONDITIONS)],
                ];
        }
}

Widget:

<?php DynamicFormWidget::begin([
            'widgetContainer' => 'wrapper-prices',
            'widgetBody' => '.container-items',
            'widgetItem' => '.item',
            'limit' => 30,
            'min' => 1,
            'insertButton' => '.add-item',
            'deleteButton' => '.remove-item',
            'model' => count($prices) ? $prices[0] : new \app\models\Price(),
            'template' => $this->render('_price-item', [
                'i' => 0,
                'form' => $form,
                'model' => count($prices) ? $prices[0] : new \app\models\Price(),
            ]),
            'formId' => 'dynamic-form',
            'formFields' => [
                'credits',
                'price',
                'reduced_price',
                'discount',
                'start',
                'end',
                'active',
            ],
        ]); ?>

mysql:

CREATE TABLE `price` (
  `id` int(11) NOT NULL,
  `credits` int(11) NOT NULL,
  `price` float NOT NULL,
  `reduced_price` float DEFAULT NULL,
  `discount` float DEFAULT NULL,
  `start` datetime DEFAULT NULL,
  `end` datetime DEFAULT NULL,
  `active` smallint(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Can anybody tell me, what is wrong ? my head almost burns

Muhammad Omer Aslam

It's your first 2 rules

[['credits'], 'integer', 'required'],
[['price'], 'integer','integerOnly' => false,'required', 'min' => 0, 'max' => 10000],

You are setting 2 core validators integer , required in one rule which is wrong. The integer for example validator takes max or min parameters and that too as an associative array 'min'=>10,and assigns the property values like $obj->min=10, and your code would force the integer validator to interpret 'required' as 0=>'required' , which clearly explains the error above.

Unknown Property – yii\base\UnknownPropertyException Setting unknown property: yii\validators\NumberValidator::0

Chang you rules method to

 public function rules()
        {
            return [
                [['credits','price'], 'required'],
                [['price'], 'integer','integerOnly' => false, 'min' => 0, 'max' => 10000],
                [['reduced_price','discount'],'integer','integerOnly' => false,'min' => 0, 'max' => 10000],
                [['start','end'],'format' => 'php:Y-m-d H:i:s'],
                [['active','credits'], 'integer'],
                [['active'], 'in', 'range' => array_keys(self::$_CONDITIONS)],
                ];
        }

Update

Your 4th rule will also be throwing error should be

[['start','end'],'datetime','format' => 'php:Y-m-d H:i:s'],

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Setting unknown property: yii\web\UrlRule::GET

Setting unknown property: yii\grid\GridView::export

Setting unknown property: yii\console\ErrorHandler::errorAction on linux server

Undefined property on unknown property

Eerror in social login in Yii2: Setting unknown property: yii\web\Application::authClientCollection

Yii2 Login from DB (Setting unknown property: app\models\User::password_hash)

Yii2 Setting unknown property: yii\filters\auth\HttpBearerAuth::formats

Kartik's yii2-grid: Setting unknown property: kartik\grid\GridView::panel

Yii2 migrate Setting unknown property: yii\caching\FileCache::backuprestore

Unknown setting 'hosts' for elasticsearch

Setting the property of a property

Setting a property of a property in a struct?

Unknown mappedBy in:... referenced property unknown

Setting property in Immediate Window not setting?

AttributeError: Unknown property axisbg

unknown property 'optimization'

Sorting on a unknown property

CssLint : Unknown property "fill"

Qt - Unknown property transform

AttributeError: Unknown property yerr

AttributeError: Unknown property column

Unknown Property in a return type

InvalidValueError: unknown property adress

Webpack error: configuration.module.rules[0] has an unknown property 'query'

Setting an instance property to a static property

Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#0' while setting bean property 'sourceList'

Setting the property in a Map

Kubernetes - Setting System property

setting a property in __init__