THINKPHP5 Note Three: Creating a base class

Source: Internet
Author: User

Before you do the project, be sure to deploy your own "base class", which is very important. For example, to access the relevant controller in the Member Center, does this type of controller have a "login limit" to access the member-related controllers?

First, create three major base classes

Original base class

Location: thinkphp\apps\common\controller\base.php

Function: The content under the Base module, the index module, and the admin module can all be called

Code:

<?PHP/** * Original base class **/namespaceApp\common\controller;use Think\controller;classBase extends controller{ Publicfunction _initialize () {parent::_initialize (); Echo'Original base class'; }     Publicfunction Test1 () {return 'test1'; }}

Index module base class

Location: thinkphp\apps\common\controller\base.php

Function: The controller under the index module, "Inherit base class" and "Call base class"

Code:

<? PHP /*  */namespace  app\index\controller;use  app\common\controller\base; class Indexbase extends  base{    public  function _initialize ()    {        parent::_initialize ();    }      Public function index ()    {            }}

Admin module base class

Location: thinkphp\apps\common\controller\base.php

Role: The controller under the admin module, "Inherit base class" and "Call base class"

Code:

/**/namespace  app\admin\controller;use app\admin\controller\adminbase; class Index extends adminbase{    public  function _initialize ()    {        parent::_initialize () ; Public Function  index ()    {        return $ this      Fetch ();    } }

(User module base class, if there is a member, this also must be created)

The primary purpose of creating a base class is " inherit " and " invoke "

THINKPHP5 Note Three: Create a base class

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.