The example in this article describes the _initialize method in thinkPHP. Share it with everyone for your reference, the details are as follows:
The _initialize method of the subclass automatically calls the _initialize method of the parent class. As for PHP's constructor construct, if you want to call a method of the parent class, you must explicitly call parent::__construct();
<?php class BaseAction extends Action { // 继承Thinkphp protected function _initialize() { // thinkphp中的函数 echo "Base class"; } }
If the subclass does not have an _initialize method in the subclass constructor , the _initialize method of the parent class is called by default.
Output: Base class
If there is, execute your own _initialize method.
Output: hello I am child
If executed simultaneously, write like this
<?php class IndexAction extends BaseAction { public function _initialize(){ // 如果子类存在initialize,则不执行父类的内容 parent::_initialize(); // 加上这一句,才执行父类的初始化函数 echo "hello I am child"; } }
Output: Base class hello I am child
I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.
For more articles related to example analysis of the _initialize method in thinkPHP, please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
