public function actionCreate(): Response|string
{
$user = new UserForm();
if ($user->load(Yii::$app->request->post()) && $user->validate()) {
try {
$user->username = $user->email;
$user->setPassword($user->password);
$user->save();
return $this->redirect(['view', 'id' => $user->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('create', [
'model' => $user,
]);
}
<?php
namespace backend\modules\settings\forms\user;
use Yii;
use core\entities\user\User;
use yii\helpers\ArrayHelper;
/**
* Class UserForm
* @package backend\modules\settings\forms
*
* @property string $password
* @property string $username
* @property string $email
* @property string $password_hash
* @property integer $status
* @property integer $created_at
* @property string $profile
*/
class UserForm extends User
{
public $username;
public $email;
public $password;
public $status;
public $created_at;
public $updated_at;
public $password_hash;
public function rules(): array
{
return [
[['email'], 'required'],
[['username', 'email'], 'unique', 'targetClass' => User::class],
[['email'], 'email'],
[['status'], 'safe'],
[['created_at', 'updated_at', 'id'], 'integer'],
[['password', 'password_hash'], 'string', 'min' => 6],
['status', 'default', 'value' => User::STATUS_ACTIVE],
['status', 'in', 'range' => [User::STATUS_ACTIVE, User::STATUS_DELETED]],
];
}
public function getRolesList(): array
{
return ArrayHelper::map(\Yii::$app->authManager->getRoles(), 'name', 'description');
}
public function getStatusList(): array
{
return User::getStatuses();
}
}
<div class="col-md-12">
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title"><?= Html::encode($this->title) ?></h3>
</div>
<?php $form = ActiveForm::begin([
'id' => 'user-create-form',
'options' => ['class' => 'form-horizontal'],
]) ?>
<div class="box-body">
<div class="form-group">
<?= Html::activeLabel($model, 'Email', ['for' => 'user-email', 'class' => 'col-sm-3 control-label']) ?>
<div class="col-sm-6">
<?= Html::activeTextInput($model, 'email', ['class' => 'form-control']) ?>
<?= Html::error($model, 'email') ?>
</div>
</div>
<div class="form-group">
<?= Html::activeLabel($model, 'Пароль', ['for' => 'user-password', 'class' => 'col-sm-3 control-label']) ?>
<div class="col-sm-6">
<?= Html::activePasswordInput($model, 'password', ['class' => 'form-control']) ?>
<?= Html::error($model, 'password') ?>
</div>
</div>
<div class="form-group">
<?= Html::activeLabel($model, 'Статус', ['for' => 'user-status', 'class' => 'col-sm-3 control-label']) ?>
<div class="col-sm-6">
<?= Html::activeDropDownList($model, 'status', User::getStatuses(), ['class' => 'form-control']) ?>
<?= Html::error($model, 'status') ?>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-default">Отменить</button>
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success pull-right']) ?>
</div>
<?php ActiveForm::end() ?>
</div>
</div>
</div>
$user->save();смотрю какие данные приходят (print_r($user);), а выводится куча всего, а конце вот это: