【问题标题】:Yii2 editable Internal server error on host only (Class yii\helpers\json not found)Yii2 editable Internal server error on host only (Class yii\helpers\json not found)
【发布时间】:2018-07-15 20:16:33
【问题描述】:

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

我在本地电脑上写的,可编辑工作正常。

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

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

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>"

响应文本

所以原因是: Class yii\helpers\json not found 但是在我的控制器中,我使用了 yii json helper,正如您在我的控制器中看到的那样:

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 上收到此错误。 任何帮助都会很好!

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-05
      • 2022-12-08
      • 1970-01-01
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多