TP Framework Summary (II)

Source: Internet
Author: User

First, function libraries and class libraries

The common library of functions in the project is to be encapsulated in the project common/function.php directly called in the project () [function ();]

The import method is thinkphp built-in class library import method, provides the convenient and flexible file import mechanism, can replace the ph require and include method completely.

For example:

Import ("MyApp.Action.UserAction");

Impot ("Think.Util.Array");

Import ("ORG. Util.page ");

Second, the right to control

Class Baseaction extends action{

Public _initialize () {

echo "Login verification First";

}

}

Class Indexaction extends baseaction{
Public Function index () {

Perform login verification before access

$this->display ();

}

}

Example::

Build a cross-project URL

__root__. " /admin.php/index/index

To determine the type of request:

$this->isget ();//Whether it is a GET request

$this->ispost ();//Whether it is a POST request

TP Hollow Operation (_empty ())

<?php

Class Cityaction extends action{

Public Function _empty ($name) {

To parse all the city's operations into the cities method

$this->city ($name);

}

Protected method

protected function City ($name) {

Echo $name;

}

}

?>

Operation of an empty module

  1. <? PHP
  2. class emptyaction extends Action{
  3. public function index() {
  4. //According to the current module name to determine the operation of the city to perform
  5. $cityName = module_name;
  6. $thisCity($cityName);
  7. }
  8. //Note the city method itself is the protected method
  9. protected function City($name) {
  10. //And $name this city-related treatment
  11. Echo ' current city ' . $name;
  12. }
  13. }
  14. ?>

Examples of using empty modules in a project:

thinkphp support for pseudo-static URL settings

' Url_html_suffix ' = '. shtml '

URL Routing

  1. ' url_router_on ' = = true, //Turn on routing
  2. ' Url_route_rules ' = = Array( //define Routing rules
  3. ' news/:year/:month/:d ay ' = = array(' news/archive ', ' Status=1 ' ),
  4. ' news/:id ' = ' news/read ',
  5. ' news/read/:id ' = ' /news/:1 ',
  6. ),

Access to LOCALHOST/TPSHOP/INDEX.PHP/NEWS/10 will access the Index/show method

TP Framework Summary (II)

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.