Talk about: phpyaf framework extension Practice 2-multi-module

Source: Internet
Author: User
Although the configuration of multiple modules may be controversial, the development efficiency and deployment efficiency can be accelerated in the early stage of the project. if the project develops with more resources, you can consider splitting the modules. Yaf also supports multi-module configuration. let's take a look at how yaf configures multiple modules.

Although the configuration of multiple modules may be controversial, the development efficiency and deployment efficiency can be accelerated in the early stage of the project. if the project develops with more resources, you can consider splitting the modules. Yaf also supports multi-module configuration. let's take a look at how yaf configures multiple modules.

Yaf multi-module configuration

For example, we want to add an api module for app retrieval and use, and add an admin module for background management.

Add the following to the configuration file:

application.modules = Index,Api,Admin

Create a New modules Directory under The applicaiton Directory. the directory structure is as follows:

Yaf multi-module directory example

The Admin and Api directories are the same as the configured modules. you can create the controllers and views directories in each module directory as controllers and views, the only pity is that files in models under the module do not support automatic loading. Therefore, some business methods under the module can only be placed in the application/models directory.

When do I need to create a module?

Generally, if the module has a unified control method, you can consider creating a new module. if the preceding example api module is used for app retrieval, a unified data output method can be encapsulated. The admin module can encapsulate authorization and verify logon. For a unified encapsulation method, see the controller parent class in the library:

Parent class of each yaf module

Summary

In the initial stage of the project, multiple modules can be used to reuse code and facilitate management. We only need to consider the possibility of splitting modules in the future, and try to avoid high coupling between modules, because such problems are sometimes easy to develop in the same project, so pay special attention to them. In addition, you must pay attention to permission access during deployment. for example, the admin module can restrict ip access and the internal interface module can only allow access within the server.

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.