ThinkPHP installation and Setup

Source: Internet
Author: User
This article is the first of ThinkPHP series tutorials. There are seven articles in this series. We will introduce this excellent Chinese open-source php framework in detail from simplicity to complexity, if you need it, you can follow it.

This article is the first of ThinkPHP series tutorials. There are seven articles in this series. We will introduce this excellent Chinese open-source php framework in detail from simplicity to complexity, if you need it, you can follow it.

Prerequisites: This tutorial applies to ThinkPHP 3.2 +

In the next few days from today, ThinkPHP series of tutorials will be released, with a total of seven articles. You can click here to add to your favorites.

1. Install

There are many ways to install ThinkPHP. You can download ThinkPHP directly on the official website. After downloading ThinkPHP, You can decompress it directly. Alternatively, you can download ThinkPHP from the Git address officially maintained by ThinkPHP.

JB51:

Github: https://github.com/liu21st/thinkphp

Oschina:

Code: https://code.csdn.net/topthink2011/ThinkPHP

Of course, as a popular PHP framework, you can also directly use composer to install it:

Composer create-project topthink/thinkphp your-project-name

2. Set

You can install ThinkPHP in the lab building. So now we start to learn ThinkPHP Step 1: Set ThinkPHP. The original appearance of a framework may not meet your development needs, but you can set it to meet your development needs. When learning ThinkPHP configuration, you must first understand that the definition formats of all configuration files in the ThinkPHP framework are defined by returning the PHP array.

<? Phpreturn array ('url _ ROUTER_ON '=> true, 'url _ ROUTE_RULES' => array ('blogs/: id' => array ('index/read '), 'Article/: id' => array ('Article/show'), 'url _ MAP_RULES '=> array ('new/top' => 'index/top? Type = top '), 'db _ type' => 'mysql', 'db _ host' => 'localhost', 'db _ name' => 'thinkdatabase ', 'db _ user' => 'root', 'db _ pwd' => 'Password', 'db _ port' => '123 ', 'db _ prefix' => 'think _',);

Note: The configuration parameters (level-1 parameters) of ThinkPHP are case-insensitive, because the configuration parameters are converted to lower-case parameters regardless of the upper case or lower case. However, we recommend that you use uppercase letters to configure parameters in order to better conform to the specifications during programming. In the first configuration of URL_ROUTER_ON above, we have enabled the routing rewrite function to lay the foundation for the later URL_ROUTE_RULES (which will be detailed later in the routing section ). The last few configuration items with DB _ indicate setting the parameters for connecting to the database. Almost every web application uses the database. These settings are the basis for further study.

<? Phpreturn array ('user _ config' => array ('user _ auth' => true, 'user _ type' => 2 ,),);

USER_AUTH and USER_TYPE in USER_CONFIG are case sensitive.

After learning about the ThinkPHP configuration format, let's take a look at the configuration loading sequence of ThinkPHP and understand that the configuration item loading sequence is very important during development, because in the configuration with the same name, the post-loaded configuration will overwrite the previously loaded order, but only the post-loaded order will take effect.

Conventional configuration-> application configuration-> mode configuration-> debugging configuration-> Status Configuration-> module configuration-> extended configuration-> dynamic configuration

The above sequence is the loading sequence of ThinkPHP configurations. In general, these configurations are automatically loaded. The most Common operation is Application configuration. The default operation is in the Application/Common/Conf/config. php file. During development, we can set our own configuration here. If you are not familiar with the value you can configure, you can open the ThinkPHP/Conf/convention. php file to view the corresponding configuration items.

Read Configuration

During the development process, we sometimes need to read the configuration value of the application and use C ('configuration parameter name') to read the configuration in ThinkPHP. For example:

$ Model = C ('url _ model ');

Or

$ Model = C ('url _ model ');

Both are equivalent and can read the system's URL access mode setting value, because the configuration items in ThinkPHP are case-insensitive. However, we recommend that you use uppercase letters.

You can use the initial character of config to remember the C () method.

The above is all about THINKPHP installation and configuration. I hope you will like it.

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.