ThinkPHP _ initialize method instance analysis, thinkphpu method example

Source: Internet
Author: User

ThinkPHP _ initialize method instance analysis, thinkphpu method example

This example describes the _ initialize method in thinkPHP. We will share this with you for your reference. The details are as follows:

The _ initialize method of the subclass automatically calls the _ initialize method of the parent class. Construct of php, if you want to call the method of the parent class, you must call parent :__ construct () in the subclass construct display ();

<? Phpclass BaseAction extends Action {// inherits Thinkphp protected function _ initialize () {// echo "Base class ";}}

If the subclass does not have the _ initialize method, the _ initialize method of the parent class is called by default.

Output: Base class

If yes, execute your own _ initialize method.

Output: hello I am child

If the statement is executed at the same time, write the statement as follows:

<? Phpclass IndexAction extends BaseAction {public function _ initialize () {// If the subclass has initialize, the content of the parent class parent: _ initialize () is not executed (); // Add this sentence to execute the initialization function echo "hello I am child";} of the parent class ";}}

Output: Base class hello I am child

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.