没有不值得去解决的问题,也没有不值得去学习的技术!

How to Use the Yii2 Debugger When Developing RESTful Applications

To view the debug data for the GET request to http://www.cmcp-api.localhost/v1/pages made in Postman, click the Tag link corresponding to the respective URL

1. Open http://frontend.cmcp-api.localhost/ in the browser. A debugger toolbar appears at the bottom of the page and can be expanded by clicking, as shown in Figure 1.

Open http://frontend.cmcp-api.localhost/ in the browser. A debugger toolbar appears at the bottom of the page and can be expanded by clicking
Figure 1

2. In Postman, make a GET request to http://www.cmcp-api.localhost/v1/pages. It returns a 200 response, but no debugger toolbar appears, as shown in Figure 2.

In Postman, make a GET request to http://www.cmcp-api.localhost/v1/pages. It returns a 200 response, but no debugger toolbar appears
Figure 2

3. Continuing from step 1, click the Yii logo on the debugger toolbar to open the available debug data, as shown in Figure 3.

Continuing from step 1, click the Yii logo on the debugger toolbar to open the available debug data
Figure 3

4. The URL for the frontend application’s debugger is http://frontend.cmcp-api.localhost/debug/default/index, as shown in Figure 4.

The URL for the frontend application's debugger is http://frontend.cmcp-api.localhost/debug/default/index
Figure 4

5. Based on the analysis of the frontend application’s debugger URL, simply replacing frontend with www gives the URL for the API application’s debugger. Open http://www.cmcp-api.localhost/debug/default/index, as shown in Figure 5.

Based on the analysis of the frontend application's debugger URL, simply replacing frontend with www gives the URL for the API application's debugger. Open http://www.cmcp-api.localhost/debug/default/index
Figure 5

6. To view the debug data for the GET request to http://www.cmcp-api.localhost/v1/pages made in Postman, click the Tag link corresponding to the respective URL, as shown in Figure 6.

To view the debug data for the GET request to http://www.cmcp-api.localhost/v1/pages made in Postman, click the Tag link corresponding to the respective URL
Figure 6

7. The Log Messages page contains the debug data for the GET request to http://www.cmcp-api.localhost/v1/pages made in Postman, as shown in Figure 7.

The Log Messages page contains the debug data for the GET request to http://www.cmcp-api.localhost/v1/pages made in Postman
Figure 7

8. There is an error in the Log. Click to view it, as shown in Figure 8.

There is an error in the Log. Click to view it
Figure 8

9. Referring to the URL https://www.shuijingwanwq.com/2018/01/10/2206/ , step 65 needs adjustment because ‘model/*’ is missing, as shown in Figure 9.

PHP

        'i18n' => [
            'translations' => [
                'model/*'=> [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'forceTranslation' => true,
                    'basePath'=>'@common/messages',
                    'fileMap'=>[
                    ],
                ],
                'app'=> [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'forceTranslation' => true,
                    'basePath'=>'@api/messages',
                    'fileMap'=>[
                    ],
                ],
                '*'=> [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'forceTranslation' => true,
                    'basePath'=>'@api/messages',
                    'fileMap'=>[
                    ],
                ],
            ],
        ],

Referring to the URL https://www.shuijingwanwq.com/2018/01/10/2206/ , step 65 needs adjustment because 'model/*' is missing
Figure 9

10. Make the request again in Postman, then reopen http://www.cmcp-api.localhost/debug/default/index. Select the latest record and click to enter; you will find that the error in the Log has been fixed, as shown in Figure 10.

Make the request again in Postman, then reopen http://www.cmcp-api.localhost/debug/default/index. Select the latest record and click to enter; you will find that the error in the Log has been fixed
Figure 10

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系