- 1 A Brief Introduction To The Secondary Development Of ZenTaoPHP
- 2. ZenTaoPHP Framework Extension Mechanism
- 3. ZenTaoPHP Framework API Mechanism
- 4 ZenTaoPHP Framework Command Line Mechanism
Extension Of Control
- 2022-05-09 15:53:02
- Kelsea
- 1780
- Last edited by Hongyan on 2022-05-09 16:51:44
- Share links
Extension Of Control
There are two ways to extend the control of an existing module, one is to cover the existing method, and the other is to add a new method. Let's see how to expand.
1. File naming rules
Whether overwriting an existing method or adding a new method, the extension file is saved under the ext/control directory with the name of the method. File names are all lowercase.
For example, taking the User module as an example, if we want to redefine its registration logic, we only need to create register.php under extension/custom/user/ext/control, and then implement the code.
If we want to add an open login function to the User module, such as called oauth, we only need to create oauth.php under extension/custom/user/ext/control, and then implement the code.
2. Standalone extension code
When extending the control, it can be completely independent, or it can reuse the methods defined in the control by the main code. The example below is completely self-contained.
class user extends control
{
public function register()
{
$this->view->header->title = 'getsid';
$this->view->sid = session_id();
$this->view->test = $this->misc->test();
$this->display();
}
}
Please pay attention to the definition of the class name: user, which is derived from the control base class. Such definitions are completely independent.
3. Inheritance extension
The example above is about the independent extension, but most of the time we want to reuse the original code of ZenTao, in this case, we could achieve it by inheriting the extension.
class myUser extends user
{
public function register()
{
....
$this->process() // process method is defined in ../../control.php
}
}
The inherited user class has been automatically loaded into memory via autoload, just define the class name myUser (my + module name), which is derived from the user class, so that the process method of the parent class user can be called in the register method.
4. Limitation
A control method can only have one extension due to the limitation of the framework loading mechanism.
Support
- Book a Demo
- Tech Forum
- GitHub
- SourceForge
About Us
- Company
- Privacy Policy
- Term of Use
- Blogs
- Partners
Contact Us
- Leave a Message
- Email Us: [email protected]