我试着调用一个设置窗体,它显示了用于将数据保存到价格数据库中的输入窗体。
我的模型在渲染过程中抛出上述异常:
**未知属性- yii\base\未知属性异常
正在设置未知属性:yii\验证器\数字验证器::0**
**_price-item:**行出错
$form->field($model, "[{$i}]credits")->textInput(['maxlength' => 8])
产品型号:
<?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)],
];
}
}
小工具:
<?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;
谁能告诉我,怎么了?我的头都快烧起来了
2条答案
按热度按时间mnowg1ta1#
这是你的前两条规则
您在一个规则中设置了两个核心验证器
integer
、required
,这是错误的。例如,integer
验证器接受max
或min
参数,并将其作为关联数组'min'=>10
,并分配类似于$obj->min=10
的属性值,您的代码将强制整数验证器将'required'
解释为0=>'required'
,这清楚地解释了上述错误。未知属性- yii\base\UnknownPropertyException正在设置未知属性:yii\验证器\数字验证器::0
昌佑规法要
更新
你的第四条规则也将抛出错误应该是
[['start','end'],'datetime','format' => 'php:Y-m-d H:i:s'],
我也更新了上面的代码块。
8mmmxcuj2#
正确的工作规则是:
"感谢穆罕默德"