New Api App for YII2 Premium Edition

Source: Internet
Author: User
Tags yii

First copy the backend to the API at the root of the project:

CP Backend/api-r

Copy API Environment

Cp-a environments/dev/frontend environments/dev/-a environments/prod/frontend Environments/prod/api

Modify the code after the environments/index.php file (mainly adding some API-related code):

return [    ' Development ' = [        ' Path ' = ' dev ', ' setwritable ' = [            ' Backend/runtime ', ' backend/web/assets ', ' frontend/runtime ', ' frontend/web/assets ', ' Api/runtime ', ' api/web/assets ',        ], ' setexecutable ' = [            ' Yii ',        ], ' setcookievalidationkey ' = [            ' backend/config/main-local.php ', ' frontend/config/main-local.php ', ' api/config/main-local.php ',        ],    ], ' Production ' = [        ' Path ' = ' prod ', ' setwritable ' = [            ' Backend/runtime ', ' backend/web/assets ', ' frontend/runtime ', ' frontend/web/assets ', ' Api/runtime ', ' api/web/assets ',        ], ' setexecutable ' = [            ' Yii ',        ], ' setcookievalidationkey ' = [            ' backend/config/main-local.php ', ' frontend/config/main-local.php ', ' api/config/main-local.php ',        ],    ],];

Then execute the initialization command:

PHP Init

Then remember to add the following code to the last line of common/config/bootstrap.php:

dirname (dirname(__dir__)). '/api ');

Modify the configuration file api/config/main.php

return [    ' id ' = ' app-api ',    //    ' controllernamespace ' = ' api\controllers ', ]

Finally, the API inside the controller and other namespaces have to modify the file.

Resources

    • On the original YII2 framework, create a new API application
    • First Lecture: Basic configuration

Source: Http://www.getyii.com/topic/28

New Api App for YII2 Premium Edition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.