weixin_33709364 2019-04-23 10:41 采纳率: 0%
浏览 28

Yii2 Kartik可编辑小部件

I have a problem with my Kartik input text editable widget. It affected on the tema column in my table. The problem is, on my chrome developer tool it returns an "Internal server error" on the AJAX processing. The response header's content is : Content-Type: application/json; charset=UTF-8 but the connection remains close. Is there anything wrong with my code? Note : the initial value of the editable's label is NOT SET (which should be the value of "tema" column retrieved from my $model->tema). The model name is Home.

My 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,
           ]);

    }


The view file

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']
    ]);         
?>



Please help. Have spent two days on this. Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 汇编语言除法溢出问题
    • ¥65 C++实现删除N个数据列表共有的元素
    • ¥15 Visual Studio问题
    • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波
    • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗