Thinkphp Framework Foundation

Source: Internet
Author: User

Environmental Requirements
    • PHP5.3 above version ( Note: Php5.3dev version and PHP6 are not supported )

Directory structure  

After downloading the 3.2 framework, unzip to the web directory below and you can see the initial directory structure as follows:

  1. www WEB部署目录(或者子目录)
  2. ├─index.php 入口文件
  3. ├─README.md README文件
  4. ├─Application 应用目录
  5. ├─Public 资源文件目录
  6. └─ThinkPHP 框架目录

Where the framework directory thinkphp is structured as follows:

  1. ├─ThinkPHP 框架系统目录(可以部署在非web目录下面)
  2. │ ├─Common 核心公共函数目录
  3. │ ├─Conf 核心配置目录
  4. │ ├─Lang 核心语言包目录
  5. │ ├─Library 框架类库目录
  6. │ │ ├─Think 核心Think类库包目录
  7. │ │ ├─Behavior 行为类库目录
  8. │ │ ├─Org Org类库包目录
  9. │ │ ├─Vendor 第三方类库目录
  10. │ │ ├─ ... 更多类库目录
  11. │ ├─Mode 框架应用模式目录
  12. │ ├─Tpl 系统模板目录
  13. │ ├─LICENSE.txt 框架授权协议文件
  14. │ ├─logo.png 框架LOGO文件
  15. │ ├─README.txt 框架README文件
  16. │ └─index.php 框架入口文件

Entry file

Thinkphp uses a single entry mode for project deployment and access, and regardless of what functionality is completed, an application has a unified (but not necessarily unique) portal.

It should be said that all applications start with a portal file, and the entry files for different applications are similar.

By default, the 3.2 version of the framework already comes with an app portal file (and the default directory structure), which reads as follows:

    1. define(‘APP_PATH‘,‘./Application/‘);
    2. require ‘./ThinkPHP/ThinkPHP.php‘;

If you change the project directory (for example, to change to Application Apps ), you only need to alter the App_path constant definition in the portal file:

    1. define(‘APP_PATH‘,‘./Apps/‘);
    2. require ‘./ThinkPHP/ThinkPHP.php‘;

Note: The definition of App_path supports relative paths and absolute paths, but must end with "/"

If you adjust the location or directory name of the framework core directory, you only need to modify it:

    1. define(‘APP_PATH‘,‘./Application/‘);
    2. require ‘./Think/ThinkPHP.php‘;

You can also define a single Think_path constant to introduce:

    1. define(‘APP_PATH‘,‘./Application/‘);
    2. define(‘THINK_PATH‘,realpath(‘../Think‘).‘/‘);
    3. require THINK_PATH.‘ThinkPHP.php‘;

As with App_path, the Think_path path definition must also end with a "/".
Defining an absolute path for Think_path and App_path increases the efficiency of the system's loading.

Automatically create a table of contents

The default welcome page is displayed the first time you access the application portal file, and a default application module home is generated automatically.

Next look at the original empty Application directory below, has automatically generated the public module Common , the default Home module and Runtime The directory structure of the runtime directory:

  1. Application
  2. ├─Common 应用公共模块
  3. │ ├─Common 应用公共函数目录
  4. │ └─Conf 应用公共配置文件目录
  5. ├─Home 默认生成的Home模块
  6. │ ├─Conf 模块配置文件目录
  7. │ ├─Common 模块函数公共目录
  8. │ ├─Controller 模块控制器目录
  9. │ ├─Model 模块模型目录
  10. │ └─View 模块视图文件目录
  11. ├─Runtime 运行时目录
  12. │ ├─Cache 模版缓存目录
  13. │ ├─Data 数据目录
  14. │ ├─Logs 日志目录
  15. │ └─Temp 缓存目录

If you are not under the Windows environment, you need to set writable permissions on the app directory to be Application automatically generated.
If it is not debug mode, the file will be generated under the runtime directory common~runtime.php (application compilation cache file).

Controller

We can find a IndexController.class.php file under the auto-generated Application/home/controller directory, which is the default index controller file.

The controller class is named by: Controller name (hump method, first letter capitalization) +controller

Controller files are named by: class name +class.php (class file suffix)

The default welcome page is actually the index action method of the index controller class under the home module that we are accessing, we modify the default index action method as follows:

Namespace Home\controller;use Think\controller;class Indexcontroller extends Controller {public    function index () {        echo ' hello,world! ';    }}

Run the app portal file again and the browser will hello,world! display:.

Let's look at the controller class, the beginning of the Indexcontroller controller class is the namespace definition:

    1. namespace Home\Controller;

This is the system's specification requirements, indicating that the current class is the controller class under the Home module , the namespace and the actual controller file is located in the same path Home\Controller\IndexController , that is, the class corresponding controller file is located under the application directory Home/Controller/IndexController.class.php , if you change the current module name, then the namespace of the Controller class needs to be modified as well.

2.use Think\Controller;

Indicates that the introduction of the Think\controller namespace facilitates direct use. So

Use Think\controller; class Indexcontroller extends Controller

Equivalent to using:

class Indexcontroller extends \think\controller
Naming conventions

The following naming conventions should be followed as far as possible during development with thinkphp:

Class files are all based on the. class. PHPis a suffix (this refers to a class library file that is used internally by thinkphp, which does not represent an externally loaded class library file), using theHump MethodNamed, andCapitalize first letter, such as Dbmysql.class. php; The namespace address of the class is the same as the path address , for example, the path where the Home\controller\usercontroller class should be application/home/controller/usercontroller.class. php; Ensure that file naming and invocation are case-sensitive because of the sensitivity of the case to the Unix-like system (and thinkphp under debug mode, even if the Windows platform checks the case); the class name and file name match (including the above-mentioned capitalization), such as the Usercontroller class file name is Usercontroller.class. PHP, the file name of the Infomodel class is Infomodel.class. PHP, and the class naming of different classes have certain specifications, such as functions, configuration files, and other class library files are generally based on . PHP suffix (third-party introduced do not require); the name of the function uses lowercase letters and underscores , such as Get _client_ip; The method is named using the Hump method, and the first letter lowercase or use underscore "_", such as getusername,_parsetype, usually the method that starts with an underscore is a private method, the name of the property uses the Hump method, and the first letter lowercase or use the underscore "_" , such as TableName, _instance, properties that usually begin with an underscore are private properties, functions or methods that begin with double-underlined "__" as magical methods, such as __call and __autoload; constants are named with uppercase letters and underscores, such as Has_one and Many_to_many; The configuration parameters are named with uppercase letters and underscores, such as html_cache_on; language variables are named with uppercase letters and underscores, such as My_lang, where a language variable that starts with an underscore is typically used for system language variables, such as _class_not_ Exist_; There is no mandatory specification for the naming of variables, which can be done according to the team specification; the thinkphp template file defaults to. html as a suffix (which can be modified by configuration); Data tables and fields are named with lowercase underscores, and note that field names do not start with an underscore, such as think The _user table and the User_name field are correctly written, and data table fields such as _username may be filtered. 

Exception: In thinkphp, there is a special case of a function name, which is a single-letter capitalization function, which is usually a shortcut to some operations, or a special function. For example: A, D, S, L methods, and so on, they have a special meaning, will be known later.

Thinkphp Framework Foundation

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.