php - Problems getting instance of UploadedFile in Yii2 -


i tried upload file server using uploadedfile class, can't instance. in model:

public $arch; public function rules() {     return [[['arch'], 'file']]; } 

before $model->arch = file_xxxx.jpg

controller:

$model->arch = uploadedfile::getinstance($model, 'arch'); 

after $model->arch null

view:

$form = activeform::begin(     ['id' => 'contact-form'],     ['options' => ['enctype' => 'multipart/form-data']] ); print $form->field($model, 'arch')->fileinput()->label(false); 

you can file next way:

$model->arch = uploadedfile::getinstancebyname($name); 

where param $name name of file input field. result can null | uploadedfile - null or instance of uploaded file.

model:

namespace frontend\models;  use yii\base\model; use yii\web\uploadedfile;  class uploadform extends model {     public $file;      public function rules() {         return [[['file'], 'file']];     } } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -