A
A
arab7892015-09-10 11:06:09
Yii
arab789, 2015-09-10 11:06:09

YII. Why is the validator not working?

There is a form for uploading files, described in the model, here are the validation rules:

public function rules()
  {
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
      array('folder_id, file_name, file_txt', 'required'),
      array('folder_id', 'numerical', 'integerOnly'=>true),
      array('file_name', 'length', 'max'=>128),
                        
               array('file_txt', 'file',
      'allowEmpty' => false,
               'types'=>'txt',
      'maxSize'=>1024 * 1024, // 1 MB
      'tooLarge'=>'File is too large!',
                        
      ),
                    
      // The following rule is used by search().
      // @todo Please remove those attributes that should not be searched.
      array('file_id, folder_id, file_name', 'safe', 'on'=>'search'),
    );
  }

If you try to upload the wrong type of file, then the validator fires, but if you do not specify a file to upload, then just a blank page is displayed without errors. If I add file_txt to the first rule in required, the situation is the same. What could be the problem?
It doesn't seem to be an error..
47ce6b6cc22b4ac4a2d7cffa13912ea0.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vyachin, 2015-09-10
@vyachin

the file_txt field must be assigned in the controller yiiframework.ru/doc/cookbook/ru/form.file.upload $model->image=CUploadedFile::getInstance($model,'image');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question