$user = User::findOne($userId);
$model = new UserEditForm();
class User extends ActiveRecord
{
// тут и правила проверки и соединение с таблицей и атрибуты и всё-всё.
}
public function actionCreate() {
$model = new UserEditForm();
if($model->load($user) && $model->save()){
// redirect при успешном сохранении модели
}
return $this->renderAjax('_form-edit', [
'model' => $model,
]);
}
public function actionUpdate($id) {
$userId = (int)Yii::$app->request->get('id');
$user = User::findOne($userId);
if($model->load($user) && $model->save()){
}
return $this->renderAjax('_form-edit', [
'model' => $model,
]);
}
$userId = (int)Yii::$app->request->get('id');
/*
*переделать в метод, который будет возвращать или модель
*или сообщение о том, что нужной записи в базе нет
*
*/
$model =User::findOne($userId);
if($model->load($model)){
// что-то делаете
}
return $this->renderAjax('_form-edit', [
'model' => $model,
]);
User::findOne();
. Возможно, что ответ от базы приходит пустой. [Fri Dec 22 21:07:34.386230 2017] [lsapi:notice] [pid 21650] [client ********] [host *****] Backend log: PHP Notice: Undefined index: tel in /var/www/*****/data/www/*****/send.php on line 6\n, referer: http://*****/form.html
[Fri Dec 22 21:07:34.386279 2017] [lsapi:notice] [pid 21650] [client ********] [host *****] Backend log: PHP Notice: Undefined index: website in /var/www/*****/data/www/*****/send.php on line 7\n, referer: http://*****/form.html
$modelUserForm = $this->findModel($id);
return $this->renderAjax('_form-user', [
'modelUserForm' => $modelUserForm
]);
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://server.com/index.php');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Нужно явно указать, что будет POST запрос
curl_setopt($ch, CURLOPT_POST, true);
// Здесь передаются значения переменных
curl_setopt($ch, CURLOPT_POSTFIELDS, 's=CURL');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP Bot (http://mysite.ru)');
$data = curl_exec($ch);
curl_close($ch);
?>
http://site.ru/user/update/1
, то есть - настроить UrlManager. Запрос будет идти на контролер user в действие update и с id выбранного пользователя.actionUpdateStatus($id)
. В действии проверять, пришёл ajax запрос или какой-то другой. После этой проверки обновлять в таблице поле "статус" у выбранного пользователя.2. Может есть более элегантный способ сменить статус юзеру по клику, который предлгалает сама yii?
if($resultSql){
while ($row = mysqli_fetch_assoc()) {
/****/
}
}
public function getAssociatedArray()
{
return $this->getAssociatedProducts()->select('id')->column();
}
<?= $form->field($model, 'associatedArray')->dropDownList(Catalog::getChildCategoryList(),
[
'multiple' => true,
'class' => 'select-multiple',
'style' => 'width:100%;',
])
?>
Call to a member function isAttributeRequired() on array
// Action 1
$session = Yii::$app->session;
if($session->isActive){
$session->set('TEST', 123);
}
// Action 2
$session = Yii::$app->session;
echo $session->get('TEST');
public function safeUp()
{
$this->alterColumn('order','street', $this->string()->notNull->defaultValue(0));
}
public function safeDown()
{
$this->alterColumn('order','street', $this->string()); // будет значение по умолчанию null
}