如何解决 Yii Db 连接上的 500 错误 [英] How to solve 500 Error on Yii Db connection

查看:29
本文介绍了如何解决 Yii Db 连接上的 500 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 yii 框架上传到我的服务器.我使用字符串连接数据库是

I have uploaded yii framework into my server. i'm using string for connecting db is

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=smargavc_Konnections',
    'username' => 'smargavc_Konnect',
    'password' => '******',
    'charset' => 'utf8',
];

在这里,不知道数据库是否已连接.

Here, Wheather dont know db is connected or not.

当我尝试在邮递员中访问其余电话时,收到 500 错误

When i trying in postman to access the rest call, getting 500 errro

推荐答案

我在 web.php 中有响应配置.它造成了 500 错误的问题.

I had response configuration in web.php. It made problem of 500 Error.

 'response' => [
            'class' => 'yii\web\Response',
            'on beforeSend' => function ($event) {
                $response = $event->sender;
                if ($response->data !== null && !empty(Yii::$app->request->get('suppress_response_code'))) {
                    $response->data = [
                        'success' => $response->isSuccessful,
                        'data' => $response->data,
                    ];
                    $response->statusCode = 200;
                }
            },
        ],

我的配置中有这个.我不知道原因.但它解决了我的问题

I had this in my configuration. I dont know the reason. But it solve my issue

这篇关于如何解决 Yii Db 连接上的 500 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆