Product::rules PHP Method

rules() public method

public rules ( ) : array
return array validation rules for model attributes.
    public function rules()
    {
        return [['name, slug', 'required', 'except' => 'search'], ['name, title, description, short_description, slug, price, discount_price, discount, data, status, is_special', 'filter', 'filter' => 'trim'], ['status, is_special, producer_id, type_id, quantity, in_stock, category_id', 'numerical', 'integerOnly' => true], ['price, average_price, purchase_price, recommended_price, discount_price, discount, length, height, width, weight', 'store\\components\\validators\\NumberValidator'], ['name, title, meta_keywords, meta_title, meta_description, meta_canonical, image, image_alt, image_title', 'length', 'max' => 250], ['discount_price, discount, average_price, purchase_price, recommended_price', 'default', 'value' => null], ['sku', 'length', 'max' => 100], ['slug', 'length', 'max' => 150], ['external_id', 'length', 'max' => 100], ['slug', 'yupe\\components\\validators\\YSLugValidator', 'message' => Yii::t('StoreModule.store', 'Illegal characters in {attribute}')], ['slug', 'unique'], ['status', 'in', 'range' => array_keys($this->getStatusList())], ['is_special', 'boolean'], ['length, height, width, weight', 'default', 'setOnEmpty' => true, 'value' => null], ['meta_canonical', 'url'], ['id, type_id, producer_id, sku, name, slug, price, discount_price, discount, short_description, description, data, is_special, length, height, width, weight, quantity, in_stock, status, create_time, update_time, meta_title, meta_description, meta_keywords, category_id', 'safe', 'on' => 'search']];
    }

Usage Example

 /**
  * Добавление правил для image и id, необходимо для безопасного присвоения
  */
 public function rules()
 {
     return CMap::mergeArray([['id, image, Attrs', 'safe']], parent::rules());
 }