O
O
Oleg Belyay2017-10-17 12:29:33
Yii
Oleg Belyay, 2017-10-17 12:29:33

Calling unknown method: frontend\models\Post::addRule() does not add a validation rule, what is the reason?

Calling unknown method: frontend\models\Post::addRule() does not add a validation rule, what is the reason?
Why is the method not found?

use Yii;
use frontend\models\Post;
use yii\base\DynamicModel;
use yii\db\Query;
use yii\web\UploadedFile;

$maxSize = 2097152;
$extensions = 'jpeg, jpg, png, gif';

$model = new Post();
$post = Yii::$app->request->post();
$uploadParam = $post['field_model'];
$model->addRule($uploadParam, 'image', [
       'maxSize' => $maxSize,
       'extensions' => explode(', ', $extensions),
 ])->validate();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alex stephen, 2017-10-17
@Red_Fox_My

probably because addRule is only in DynamicModel ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question