вот контролер
<?php
namespace backend\controllers;
use Yii;
use common\models\User;
use app\models\UserSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\UploadedFile;
use yii\filters\AccessControl;
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
$auth = Yii::$app->getAuthManager();
$post = Yii::$app->request->post();
$role = $auth->getRole($post['role']);
$model->file = UploadedFile::getInstance($model,'avatar');
$name=$model->file->baseName.''.$model->file->extension;
$years=date('Y');
$mounts=date('m');
if (file_exists('foto/'.$years.'/'.$mounts.'/')){} else{
mkdir(Yii::getAlias('@backend/web/').'foto/'.$years.'/'.$mounts.'/', 0775, true);
}
$model->file->saveAs(Yii::getAlias('@backend/web/').'foto/'.$years.'/'.$mounts.'/'.$name.'.'.$model->file->extension);
$path=Yii::getAlias('@backend/web/').'foto/'.$years.'/'.$mounts.'/'.$name.'.'.$model->file->extension;
$model->avatar=$path;
if($model->save()){
$auth->revokeAll($id);
$auth->assign($role, $id);}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
'auth' => Yii::$app->authManager->roles,
'read' => $role
]);
}
}
вот модель
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
use yii\web\UploadedFile;
/**
* User model
*
* @property integer $id
* @property string $username
* @property string $password_hash
* @property string $password_reset_token
* @property string $email
* @property string $auth_key
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
* @property string $password write-only password
*/
class User extends ActiveRecord implements
\yii\web\IdentityInterface
{
public $files;
const ROLE_USER = 'user';
const ROLE_ADMIN = 'admin';
const ROLE_MODER = 'moder';
const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10;
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%user}}';
}
вот вид
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->field($model, 'username')->textInput(['maxlength' => true])->label('Логин') ?>
<?= $form->field($model, 'password_hash')->passwordInput(['maxlength' => true])->label('Пароль') ?>
<?= $form->field($model, 'password_reset_token')->passwordInput(['maxlength' => true])->label('Повторить пароль') ?>
<?= $form->field($model, 'email')->textInput(['maxlength' => true])->label('Е-mail') ?>
<?= $form->field($model, 'status')->textInput() ?>
<?= $form->field($model, 'avatar')->fileInput()->label('Установите картинку аватара') ?>
<?php if($model->isNewRecord){ ?>
<?= $form->field($model, 'created_at')->hiddenInput(['value'=>$theDate])->label('') ?>
<?php }else{ ?>
<div class="form-group field-category-parent_id">
<label class="control-label" for="auth-role">Выберите роль</label>
<?= Html::dropDownList('role',0,$role,$option=['class'=>'form-control','id'=>'auth-role'])?>
</div>
<?= $form->field($model, 'id')->hiddenInput(['value'=>$model->id])->label('') ?>
<?= $form->field($model, 'updated_at')->hiddenInput(['value'=>$theDate])->label('') ?>
<?php } ?>
<?= $form->field($model, 'auth_key')->hiddenInput(['maxlength' => true,'value'=>$authKey])->label('') ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Создать' : 'Изменить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
пишет Setting unknown property: common\models\User::file и ругается на эту строку
$model->file = UploadedFile::getInstance($model,'avatar');
не подскажите в чем проблема ?