我是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}
答案 0 :(得分:7)
只是添加更新,因为至少在一方面,上面的答案可能会产生误导。
我认为除了上面提到的问题,你还有其他问题,可以通过添加“use yii \ helpers \ Json;”来解决。或类似的东西,因为Response不在你提到的命名空间内。
如果您想从控制器获得Json输出,并且如果您想使用Response类来管理动作输出,则需要使用
use yii\web\Response;
此外,使用示例:
public function actionApi() {
Yii::$app->response->format = Response::FORMAT_JSON;
return array(
"test" => "test",
"test2" => "test2"
);
}
答案 1 :(得分:4)
抱歉这是我的错。 我刚才包括这个:
use yii\helpers\Json;
解决了问题。 dep dep down现在按预期工作
答案 2 :(得分:0)
请使用此代码。
use yii\web\Response;