我的Kartik输入文本可编辑小部件出现问题。它影响了我表中的tema
列。问题是,在我的chrome开发人员工具上,它在AJAX处理中返回了“内部服务器错误”。响应标头的内容为:Content-Type: application/json; charset=UTF-8
,但连接仍为close
。我的代码有什么问题吗?注意:可编辑标签的初始值为NOT SET
(应该是从我的$model->tema
中检索到的“ tema”列的值)。型号名称为Home
。
我的HomeController:
public function actionIndex()
{
$searchModel = new HomeSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$model = new Home;
// Check if there is an Editable ajax request
if (isset($_POST['hasEditable'])) {
// use Yii's response format to encode output as JSON
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$temaId=Yii::$app->request->post('editableKey');
$query= Home::find()->where(['id'=> $temaId])->one();
// read your posted model attributes
if ($model->load($_POST)) {
// read or convert your posted information
$value = $query->tema;
$value->save();
// return JSON encoded output in the below format
return ['output'=>$value, 'message'=>''];
// alternatively you can return a validation error
// return ['output'=>'', 'message'=>'Validation error'];
} else {
// else if nothing to do always return an empty JSON encoded output
return ['output'=>'', 'message'=>''];
}
};
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'model'=>$model,
]);
}
视图文件
use kartik\editable\Editable;
<?php
echo Editable::widget([
'model' => $model,
'attribute' => 'tema',
'type' => 'post',
'value'=>$model->tema,
'header'=>'tema',
'size'=> 'lg',
'inputType' => Editable::INPUT_TEXT,
'editableValueOptions' => ['class' => 'text-success h3']
]);
?>
请帮助。已经花了两天了。谢谢!