: This article mainly introduces the development of large and medium-sized applications based on the TypechoCMS framework. if you are interested in the PHP Tutorial, refer to it. Develop large and medium-sized applications based on Typecho CMS Framework
Large and medium-sized applications are defined as: applications with more than or equal to three data tables! Sweat!
Typecho was originally a blog system. its framework system is different from the common MVC framework on the market. The main code is based on its own widgets, which is very simple as a whole.
The basic features of Typecho are as follows:
- Single Portal
- Except Db configuration, other configurations are stored in DB
- Route configuration is also stored in DB
- Create a Widget layer without a traditional Model layer
- Create an Action layer, similar to the traditional Controller layer
- Hook mechanism
- Generic Plugin mechanism. Plugin includes registering Handler of an existing Hook, extending the methods of existing widgets, registering a new front-end Route to map new actions, and registering the backend management interface.
- Supports UI themes
Why develop applications based on Typecho?
I am not an official developer of Typecho, nor am I working in segmentfault, a background organization. why do I use this niche framework?
In fact, you do not need to use Typecho. there are too many frameworks in the PHP world, so you can choose a more advanced framework.
I don't know when I began to find myself a "niche" patient, and I don't like to take the ordinary path. Just like Linux may already be small enough in the desktop field, but I like FreeBSD with a smaller number.
This is just one of my attempts.
Practice
Principle: add a Service layer based on the MVC mode.
- Layer C
As we have mentioned earlier, the concept of Action is created in Typecho, which is the basis of the C layer, but the Action is not clearly defined. So I will define a Controller base class.
- M layer
Typecho does not have the concept of Model. it directly calls SQL queries. Therefore, you must also define the Model base class.
- V layer
View files are the content carrier of views. to reduce learning costs, you can directly use them without introducing the template engine.PHP syntaxAnd directly attract execution in C.
- Service Layer
In complex applications, the biggest problem with MVC is that reusable code is not refined enough. some people are too fat at layer C and some are too fat at layer M. Introducing the Service layer helps to refine and encapsulate the Service layer and improve code reuse as much as possible.
Demo Project: Typecho Alumni plugin recording plug-in project
Code address: https ://Github. Com/web3d/plugins/tree/master/Alumni
Project code structure:
/Plugins/Alumni/Base/Action. php | Model. php | Service. php | Helper. php
/Plugins/Alumni/Model/
/Plugins/Alumni/Service/
/Plugins/Alumni/Action/
/Plugins/Alumni/views/default/
/Plugins/Alumni/Plugin. php
/Plugins/Alumni/panel. php
============
To be continued...
The above introduces the development of large and medium-sized applications based on the Typecho CMS Framework, including the PHP syntax and github content, and hopes to help those who are interested in the PHP Tutorial.