Answer the question
In order to leave comments, you need to log in
Why doesn't it work with saving kartik GridView?
Actually, here are links to the extension itself, here is the documentation on saving using GridView
, but there is a need to make changes to two models, so I will transform the code like this in the controller
if (Yii::$app->request->post('hasEditable')) {
$id = Yii::$app->request->post('editableKey');
$editableAttribute= Yii::$app->request->post('editableAttribute');
$model = Transliter::findOne($id);
$out = Json::encode(['output'=>'', 'message'=>'']);
$posted = current($_POST['Transliter']);
$post = ['Transliter' => $posted];
if ($model->load($post)) {
$model->$editableAttribute=$posted;
if($model->save()){}else{
return var_dump($model->getErrors());
}
$output = '';
$out = Json::encode(['output'=>$output, 'message'=>'']);
}
echo $out;
return;
Internal Server Error
, and if I comment on the save and return the model like thisif (Yii::$app->request->post('hasEditable')) {
$id = Yii::$app->request->post('editableKey');
$editableAttribute= Yii::$app->request->post('editableAttribute');
$model = Transliter::findOne($id);
$out = Json::encode(['output'=>'', 'message'=>'']);
$posted = current($_POST['Transliter']);
$post = ['Transliter' => $posted];
if ($model->load($post)) {
$model->$editableAttribute=$posted;
}
echo $out;
return var_dump($model->category);
yii\base\ErrorException: Undefined offset: 0 in /var/www/film.lc/vendor/yiisoft/yii2/db/Command.php:330
Stack trace:
#0 /var/www/film.lc/vendor/yiisoft/yii2/db/ActiveRecord.php(225): yii\db\Command->update()
#1 /var/www/film.lc/vendor/yiisoft/yii2/db/BaseActiveRecord.php(765): yii\db\ActiveRecord::updateAll()
#2 /var/www/film.lc/vendor/yiisoft/yii2/db/ActiveRecord.php(570): yii\db\BaseActiveRecord->updateInternal()
#3 /var/www/film.lc/vendor/yiisoft/yii2/db/BaseActiveRecord.php(636): yii\db\ActiveRecord->update()
#4 /var/www/film.lc/backend/modules/transliter/controllers/TransliterController.php(50): yii\db\BaseActiveRecord->save()
#5 /var/www/film.lc/vendor/yiisoft/yii2/base/InlineAction.php(57): backend\modules\transliter\controllers\TransliterController->actionIndex()
#6 /var/www/film.lc/vendor/yiisoft/yii2/base/InlineAction.php(57): ::call_user_func_array:{/var/www/film.lc/vendor/yiisoft/yii2/base/InlineAction.php:57}()
#7 /var/www/film.lc/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\InlineAction->runWithParams()
#8 /var/www/film.lc/vendor/yiisoft/yii2/base/Module.php(523): yii\base\Controller->runAction()
#9 /var/www/film.lc/vendor/yiisoft/yii2/web/Application.php(102): yii\base\Module->runAction()
#10 /var/www/film.lc/vendor/yiisoft/yii2/base/Application.php(380): yii\web\Application->handleRequest()
#11 /var/www/film.lc/backend/web/index.php(18): yii\base\Application->run()
#12 {main}
Answer the question
In order to leave comments, you need to log in
The problem is clearly here:
$posted = current($_POST['Transliter']);
$post = ['Transliter' => $posted];
if ($model->load($post)) {
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question