Answer the question
In order to leave comments, you need to log in
Why is table data not updating in Yii2?
there is a form
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
$baseUrl = Yii::$app->request->baseUrl;
?>
<div>
<?
$username = $user -> username;
$mail = $user -> email;
$phone = $user -> phone;
$ava = $user -> ava;
$status = $user -> status;
$pass = $user -> password;
$id = $user -> id;
?>
<?php $form = ActiveForm::begin([ 'method' => 'POST', 'options' => ['enctype' => 'multipart/form-data']]) ?>
<?= $form->field($EditUserAdmin, 'username')->textInput(['value' => $username]) ?>
<?= $form->field($EditUserAdmin, 'email')->textInput(['value' => $mail]) ?>
<?= $form->field($EditUserAdmin, 'phone')->textInput(['value' => $phone]) ?>
<?= $form->field($EditUserAdmin, 'password') ?>
<?= $form->field($EditUserAdmin, 'status') ?>
<?= $form->field($EditUserAdmin, 'id')->textInput(['value' => $id]) ?>
<?= $form->field($EditUserAdmin, 'ava')->fileinput() ?>
<img src='<?='../../web/'.$ava?>'> <br>
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
<?php ActiveForm::end() ?>
</div>
public function actionUsers()
{
if(Yii::$app->request->get()){
$EditUserAdmin = new EditUserAdmin();
$user = $_GET['user'];
$user_result = User::find()->where(['username' => $user]) -> one();
return $this->render('Edituseradmin',[
'EditUserAdmin' => $EditUserAdmin,
'user' => $user_result ]);
}
if(Yii::$app->request->post()){
$id = $_POST['EditUserAdmin']['id'];
$user = User::find()->where(['id' => $id]) -> one();
$user->username=$_POST['EditUserAdmin']['username'];
$user->email=$_POST['EditUserAdmin']['email'];
$user->phone=$_POST['EditUserAdmin']['phone'];
$user->password=md5($_POST['EditUserAdmin']['password']);
$user->ava=$_POST['EditUserAdmin']['ava'];
$user->status=$_POST['EditUserAdmin']['status'];
$user->update();
return Yii::$app->response->redirect(Url::to('index'));
}
$users = user::find()->all();
return $this->render('users',[
'users' => $users,
]);
}
Answer the question
In order to leave comments, you need to log in
1) Wildness .... Why do you directly access $ _POST when there is a load method
2) Instead Yii::$app->request->post()
, useYii::$app->request->isPost
1 Use instead of such constructions $_POST['EditUserAdmin']['username']
on such
Yii::$app->request->post('EditUserAdmin')['username']
Well, if you use Yii2 Yii::$app->response->redirect(Url::to('index')
this->redirect(['controller/index'])
if($user->save()){
return $user->getErrrors();
}
var_dump(Yii::$app->response->post());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question