A Brief Introduction To The Extension Mechanism

2022-05-09 15:53:02
Kelsea
466
Last edited by Hongyan on 2022-05-09 16:26:20
Share links

A Brief Introduction To The Extension Mechanism

Our ZenTao team has used a lot of PHP open-source software in the past ten years. We have encountered the same problem during the process: if we made personalized changes to the code, there is no way to follow the official version to upgrade. Better programs such as WordPress, dupral, and discuz had their own hook extension mechanism later. However, the extension mechanism is based on actions or events, and can only make partial changes to the original system, which is relatively restrictive, and there is no way to make more in-depth changes to the system. With this question in mind, when we designed the zentaoPHP framework, we paid special attention to the extensibility of the framework. Thanks to the enhancement of oop syntax after the PHP5.2 version, the zentaoPHP framework has implemented a thorough extension mechanism.

 

The functions of ZenTao are composed of individual modules, and each module will correspond to a directory, such as Project, User, and other modules. Each module is divided according to mvc, and has its own control, model, and view. At the same time, we added several other auxiliary concepts: config (configuration), lang (language), css (style), and js (js script). Through the extension mechanism of the zentaoPHP framework, the extension of any layer can be realized.

1. For the existing modules of ZenTao, the directory structure of the extension code is as follows:

extension/custom/user/ext/control/{method1.php, method2.php, ...} 
extension/custom/user/ext/model/{extend1.php, extend2.php, ...}
extension/custom/user/ext/view/{method1.html.php, method2.html.php, ...}
extension/custom/user/ext/config/{config1.php, config2.php, ...}
extension/custom/user/ext/lang/zh-cn/{lang1.php, lang2.php, ...}
extension/custom/user/ext/lang/en/{lang1.php, lang2.php, ...}
extension/custom/user/ext/css/method1/{1.css, 2.css, ...}
extension/custom/user/ext/js/method1/{1.js, 2.js, ...} 

2. For new modules, all codes need to be written in the extension/custom directory:

extension/custom/oa/control.php
extension/custom/oa/model.php
extension/custom/oa/view/{metho1.html.php, method2.html.php, ...}
extension/custom/oa/config/config.php
extension/custom/oa/css/{method1.css, method2.css, common.css, ...}
extension/custom/oa/js/{method1.js, method2.js, common.js, ...}
     
extension/custom/oa/ext/control/{method1.php, method2.php, ...} 
extension/custom/oa/ext/model/{extend1.php, extend2.php, ...}
extension/custom/oa/ext/view/{method1.html.php, method2.html.php, ...}
extension/custom/oa/ext/config/{config1.php, config2.php, ...}
extension/custom/oa/ext/lang/zh-cn/{lang1.php, lang2.php, ...}
extension/custom/oa/ext/lang/en/{lang1.php, lang2.php, ...}
extension/custom/oa/ext/css/method1/{1.css, 2.css, ...}
extension/custom/oa/ext/js/method1/{1.js, 2.js, ...} 

Developers can redefine existing functions or add new functions as long as they deploy the corresponding extension code to the corresponding directory according to our extension mechanism. Because the extension code is separated from the main code, there is no need to worry about the extension code being overwritten when the main code is upgraded. You can upgrade with confidence.

Write a Comment
Comment will be posted after it is reviewed.