使用yii2-widget-depdrop扩展名找不到Yii2 app\controllers\response

kar*_*012 3 php json yii2

我是yii2和php web app开发的新手.我正在使用dep-drop来根据父选择选择输入.现在我在yii2调试器中收到一条错误消息,

exception 'yii\base\ErrorException' with message 'Class 'app\controllers\Response' not found' in G:\xampp\htdocs\project\controllers\SalesOrderController.php:129 Stack trace: #0 [internal function]: yii\base\ErrorHandler->handleFatalError() #1 {main}
Run Code Online (Sandbox Code Playgroud)

coo*_*ool 7

只是添加更新,因为至少在一方面,上面的答案可能会产生误导.

我认为除了你上面提到的问题,你还有另外一个问题,可以通过添加"use yii\helpers\Json;"来解决.或类似的东西因为Response不在你提到的命名空间内.

如果要从控制器获得Json输出,并且如果要使用Response类来管理操作输出,则需要使用

use yii\web\Response;
Run Code Online (Sandbox Code Playgroud)

另外,使用示例:

public function actionApi() {
    Yii::$app->response->format = Response::FORMAT_JSON;
    return array(
        "test" => "test",
        "test2" => "test2"
    );
}
Run Code Online (Sandbox Code Playgroud)