thinkphp3.2.2 Common class architecture problem analysis, thinkphp3.2.2 architecture _php Tutorial

Source: Internet
Author: User

thinkphp3.2.2 Common class architecture problem analysis, thinkphp3.2.2 architecture


In this paper, the common class architecture of thinkphp3.2.2 is analyzed. Share to everyone for your reference. The specific analysis is as follows:

Before 3.13 Many projects all use the front and back common class, under Lib/action creates the baseaction as the public inherits the class, discovers 3.2.2 inside many people all use a call, so every use once to use a call, good trouble, small part deliberately lazy. The pro-test is resolved using the following methods. Interested friends can be enhanced to improve it!

thinkphp3.2.2 's so created application/common/controller/basecontroller.class.php
Copy the Code code as follows: <?php
namespace Common\controller;
Use Think\controller;
/**
* Front and rear common base class
* Modify Author:jack
* Modify Time:2014-7-12
*/
Class Basecontroller extends controller{

Public Function _initialize () {//global variable
Dump (' base class ');
$this->cfg ();
}
}

In the home/controller/zixuncontroller.class.php

Copy the Code code as follows:
<?php
namespace Home\controller;
Use Common\controller\basecontroller;
Class Zixuncontroller extends Basecontroller {

Public Function index () {
$result = $this->lists ();
Dump ($result);
}
}

Of course, in front of the background can also create their own base class, such as the background built AdminController.class.php inherit BaseController.class.php, The foreground creates HomeController.class.php inheritance BaseController.class.php each module inherits its own base class, so the project can be clearer, avoids duplicating wheels, saves a lot of things, but it must be noted that each class must declare a namespace, but the resources used can After being defined in the respective base class, you do not have to write once. For example, AdminController.class.php inherit BaseController.class.php, you do not have to write the use of Think\controller, directly using uses Common\controller\ Basecontroller can do it.

It is hoped that this article will be helpful to everyone's thinkphp framework design.

http://www.bkjia.com/PHPjc/917030.html www.bkjia.com true http://www.bkjia.com/PHPjc/917030.html techarticle thinkphp3.2.2 Common class architecture problem analysis, thinkphp3.2.2 architecture in this paper, we analyze the common class architecture problem of thinkphp3.2.2 and fore and aft platform. Share to everyone for your reference. Specific analysis ...

  • Related Article

    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.