1

I have a Yii2 advanced app with Dynagrid and with one column editable (http://demos.krajee.com/editable)

I wrote it on local PC and editable works fine.

I copied the files on my host and now I get Internal server error when trying to use Editable widget to update the value of the field.

Investigating showed me the place where error happens

POST http://.../backend/web/index.php?r=trackdata%2Findex 500 (Internal Server Error)
send @ jquery.js:9177
...

by clicking on this jquery.js I see :

xhr.send( options.hasContent && options.data || null ); with the red error flag

When introducing a console.log(xhr); before the xhr.send instruction I see :

response:"<pre>PHP Fatal Error &#039;yii\base\ErrorException&#039; with message &#039;Class &#039;yii\helpers\json&#039; not found&#039; ↵↵in .../backend/controllers/TrackdataController.php:63↵↵Stack trace:↵#0 [internal function]: yii\base\ErrorHandler-&gt;handleFatalError()↵#1 {main}</pre>"

responseText

So the reason is : Class yii\helpers\json not found But in my controller I use yii json helper as you can see in my Controller :

use yii\helpers\json;
...
if (Yii::$app->request->post('hasEditable')) 
    {
        $trackId = Yii::$app->request->post('editableKey');
        $model = Trackdata::findOne($trackId);
        $out = Json::encode(['output'=>'', 'message'=>'']);
        $post = [];
        $posted = current($_POST['Trackdata']);
        $post['Trackdata'] = $posted;
        if ($model->load($post)) 
        {
            $model->save();
            $output = '';
            $out = Json::encode(['output'=>$output, 'message'=>'']);
        } 
        echo $out;
        return;
        ...

This is the view :

<?= DynaGrid::widget([
    'columns' => [
        ...
        [
            'class' => 'kartik\grid\EditableColumn',
            'attribute'=>'vu',
            'editableOptions'=> function ($model, $key, $index) {
                return [
                    'displayValueConfig' => [1 => 'Oui', 0 => 'Non'],
                    'displayValue' => [1 => 'Oui', 0 => 'Non'],
                    'data' => [1 => 'Oui', 0 => 'Non'],
                    'value' => 0,
                    'asPopover' => true,
                    'header' => 'Vu ',
                    'inputType' => Editable::INPUT_DROPDOWN_LIST,
                ];
            }
        ],
        ...

I cannot see why I am getting this error only on the host and not on the local PC. Any help would be nice !

4

1 回答 1

1

这是奇怪的行为,但请尝试use yii\helpers\Json;J 大写的地方。

于 2017-07-31T08:16:36.117 回答