Yii2可编辑仅在主机上的内部服务器错误(未找到类yii \ helpers \ json)

时间:2017-07-29 22:10:48

标签: php json yii2-advanced-app kartik-v

我有一个带有Dynagrid的Yii2高级应用程序,并且有一列可编辑(http://demos.krajee.com/editable

我是在本地PC上写的,可编辑的作品很好。

我复制了主机上的文件,现在尝试使用可编辑小部件更新字段值时出现内部服务器错误。

调查向我展示了发生错误的地方

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

点击这个jquery.js,我看到了:

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

引入console.log(xhr)时;在xhr.send指令之前,我看到了:

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的

原因是:找不到类yii \ helpers \ json 但是在我的控制器中,我使用yii json helper,你可以在我的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;
        ...

这是观点:

<?= 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,
                ];
            }
        ],
        ...

我不明白为什么我只在主机上而不是在本地PC上收到此错误。 任何帮助都会很好!

1 个答案:

答案 0 :(得分:1)

这是一种奇怪的行为,但请尝试use yii\helpers\Json;,其中J是大写的。