Thinkphp Framework _ Learning 8

Source: Internet
Author: User

  

"cross-controller call"

When a controller executes, it can instantiate another control and access its specified method through the object.

Cross-controller calls can save our code, otherwise the same function will have to be written again in a different controller, which is a very troublesome thing.

For example: there are 10 pages, all of which are displayed in a realistic, specified data message. For example, our site's "membership number is 2 million", this information needs to be displayed on 10 pages

This data is queried through the UserController.class.php number () method.

Now the Product List page also needs to display 2 million members of the information, then in principle is GoodsController.class.php inside there is also a method number () specifically for the purpose of membership

Many controllers require the number () method if many pages need to display 2 million of the membership data.

If you can instantiate the user controller and call its number () method, you will save a lot of repetitive work.

* First create an object in the controller that requires the controller to be called, and then use that object to invoke the method of the function

The TP framework can also be used to encapsulate a number of functions, to cross the call of the controller, which is more convenient and fast

For details, see the description of the package function below, a (), R ().

system function Library: thinkphp/common/functions.php

A ("[Module/] Controller flag") instantiating the Controller object

R ([module/] Controller flag/action method) instantiating an object invokes the specified method at the same time

"Framework Execution Process Analysis"

TP Framework Internal code integration: process-oriented and OOP oriented objects

1. index.php Entry File

2. thinkphp/thinkphp.php

After the php5.3 version

There are two ways of setting constants:

Const NAME = value; The scope is determined by the current namespace

Define () scope Global

① defines a number of constants

② introduction of core files Think.class.php

Think::start ();

3. thinkphp/library/think/think.class.php

static function Start ()

① introduction of System core files

② introducing a configuration file

③ If it is a build mode, the common~runtime.php file is also generated

④ if the system is used for the first time, it will also automatically create the corresponding application directory (Home, Common, Runtime)

App::run ();

4. thinkphp/library/think/app.class.php

static function Run ()

App::init ();

Route resolution

Routing parsing , assigning modules, controllers, methods to constants

module_name = Module name

Controller_name Controller

Action_name Method

App::exec ()

instantiating a Controller object

Implementing object invocation Methods with "reflection"

To implement an object invocation method with reflection:

Thinkphp Framework _ Learning 8

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.