When you recently debugged the RESTful API sample, the following error occurred:
1 {2"Name": "Exception",3"Message": "Class Yii/web/jsonparser does not exist",4"Code":-1,5"Type": "Reflectionexception",6"File": "/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/di/container.php",7"Line": 426,8"Stack-trace": [9"#0/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/di/container.php (426): ReflectionClass->__ Construct (' Yii/web/jsonpar ... ') ",Ten"#1/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/di/container.php (364): yii\\di\\Container-> Getdependencies (' Yii/web/jsonpar ... ') ", One"#2/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/di/container.php (156): yii\\di\\Container-> Build (' Yii/web/jsonpar ... ', array, array) ", A"#3/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/baseyii.php (345): Yii\\di\\container->get (' Yii /web/jsonpar ... ', Array) ', -"#4/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/web/request.php (531): Yii\\BaseYii::createObject ( ' Yii/web/jsonpar ... '), -"#5/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/rest/createaction.php (Wuyi): yii\\web\\Request-> Getbodyparams () ", the"#6 [internal function]: Yii\\rest\\createaction->run ()", -"#7/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/base/action.php (94): Call_user_func_array (Array, Array) ", -"#8/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/base/controller.php (157): yii\\base\\Action-> Runwithparams (Array) ", -"#9/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/base/module.php (528): yii\\base\\Controller-> Runaction (' Create ', Array) ', +"#10/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/web/application.php (103): yii\\base\\Module-> Runaction (' deptinfo/create ', Array) ", -"#11/users/desktop/workspaces/php/yii2-ims/vendor/yiisoft/yii2/base/application.php (386): yii\\web\\ Application->handlerequest (Object (yii\\web\\request)) ", +"#12/users/desktop/workspaces/php/yii2-ims/api/web/index.php (): Yii\\base\\application->run ()", A"#13 {main}" at ] -}
Actually, this is oneself to dig a pit for oneself, result put oneself to sink in, the following is the code of the configuration file:
' Request ' = [ ' class ' = ' yii\web\request ', ' parsers ' and ' = ' Application/json ' = = ' Yii/web/jsonparser ', ], ],
The problem is that the configuration will be "Yii/web/jsonparser" wrong, the correct is "Yii\web\jsonparser", the namespace should be inverted slash "\" split, seemingly small problems, the results of debugging for a long time to find the reason, So when writing code configuration must be careful, so as not to be misled by themselves, wasting precious time.
Solve Yii2 Class Yii/web/jsonparser does not exist, reflectionexception problem