Implementing Model Layering in Yii 2.0 Advanced Template: Process of Data Layer, Logical Layer
1. Define:
Data Layer: Models are used to define data-related automatic verification and auto-completion and data access interfaces.
Logic Layer: Logics is used to define data-related business logic.
2. Create a new logics directory in the common directory, which is used for the logical layer of the mysql model, as shown in Figure 1
3. Create a new redis directory in the common/logics directory, which is used for the logical layer of the Redis (ActiveRecord) model, as shown in Figure 2
4. The MySQL model file in the Common/Models directory is generated by the GII tool, as shown in Figure 3
5. The Redis (ActiveRecord) model file in the Common/Models/Redis directory is the definition of the model field structure, as shown in Figure 4
6. The MySQL model file in the Common/Logics directory is business logic related, and inherits it to the \common\models\game data layer, as shown in Figure 5
API\Models
common\logics
7. The redis(activerecord) model file in the common/logics/redis directory is related to the business logic, and inherits the data layer of \common\models\redis\game, as shown in Figure 6
API\Models\Redis
common\logics\redis
API\Models
common\models
API
Common
common\models\redis\lock
common\logics\redis\lock
common\models\redis\live
common\logics\redis\live
$API
$common
8. The redis (native command) model file in the common/logics/redis directory is business logic-related, and does not need to be inherited to the \common\models\redis\game data layer, but directly inherits to \yii\redis\activerecord, as shown in Figure 7
9. The mysql model file in the api/models directory is related to business logic, and inherits it to the \common\logics\game logic layer, as shown in Figure 8
\common\models
\common\logics
10. The redis (activerecord/native command) model file in the api/models/redis directory is business logic related, inherited to the \common\logics\redis\game logic layer, as shown in Figure 9
common\models\redis\lock
common\logics\redis\lock
\common\models\redis
\common\logics\redis








