there is no error in model , but not validated

hi there

see this:


                    $model->file->saveAs('..\\..\\images\\'. $model->pic_name . '.' . $model->file->extension);


when i removed if condition, the picture was saved successfully and didnt get any error

but when i have this if condition, it returned false and pic didnt save(that means there is a error)

any suggestion?



    $model->file->saveAs('..\\..\\images\\'. $model->pic_name . '.' . $model->file->extension);

} else {

    print_r($model->getErrors()); die();


solved by scenarios, but i dont know why i had to use theme?

My link

by removing scenarios and using your way, i got this error:

Array ( [file] => Array ( [0] => The file "20140714_123039.jpg" is too big. Its size cannot exceed 2097152 bytes. ) ) 

but if it is a real error, why saved the pic?

how can i show this error msg like msgs that yii shows for rules?like required, interger, …?

If you’re using ActiveForm these should be displayed at the corresponding fields. If not you should take care about it yourself.

yes im using ActiveForm but it did not display error at the corresponding fields.

in my model i added a filed name ‘file’ and this rule:

       return [



          [['file'], 'file'],


and in my view add this:

<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>



    <?= $form->field($model, 'file')->fileInput(); ?>


    <div class="form-group">

        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>


    <?php ActiveForm::end(); ?>

should i add sth else to rules?

i want one of these:

or show error at the corresponding field or only check my rule in $model->validate() and not more

thanks for your help

Nope. It should work. If you can put together a reproduceable example please report it to issue tracker at github.

sorry, it was my fault, rendered a wrong view…

thanks for you help