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.