This article mainly introduces the installation and settings of ThinkPHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
Premise: This tutorial is applicable to ThinkPHP 3.2
In the next few days from today, a series of ThinkPHP tutorials will be released. There are seven articles in total. Students who need them can like and collect them by themselves.
1. Installation
There are many ways to install ThinkPHP. You can go directly to the official website of ThinkPHP to download it. After downloading, just unzip it; or you can Go to the Git address officially maintained by ThinkPHP to download
Of course, as a popular PHP framework, you can also install it directly with composer:
composer create-project topthink/thinkphp your-project-name
2. Setup
Just check the above installation, because ThinkPHP has already been installed in the laboratory building. So let’s start with the first step of learning ThinkPHP: setting up ThinkPHP. A framework's raw appearance may not meet your development needs, but you can set it up to do so. When learning the configuration of ThinkPHP, you must first understand: the definition format of all configuration files in the ThinkPHP framework is defined by returning a PHP array
<?php return 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' => '3306', 'DB_PREFIX' => 'think_', );
Note: ThinkPHP's configuration parameters (first-level parameters) are not case-sensitive, because regardless of uppercase or lowercase, they will eventually be converted to lowercase. However, in order to be more compliant with specifications during the programming process, it is recommended to use uppercase letters to set configuration parameters. In the first configuration above, URL_ROUTER_ON, we enable the route rewriting function, laying the foundation for the subsequent URL_ROUTE_RULES (we will talk about it in detail later in the routing chapter). The last few setting items with DB_ represent the parameters for connecting to the database. Almost every web application will use the database. These settings are the basis for our further study.
<?php return array( 'USER_CONFIG' => array( 'USER_AUTH' => true, 'USER_TYPE' => 2, ), );
For example, USER_AUTH and USER_TYPE under USER_CONFIG above are case-sensitive.
After understanding the configuration format of ThinkPHP, let’s take a look at the configuration loading sequence of ThinkPHP. Understanding the loading sequence of configuration items is very important during development, because under the configuration with the same name, the configuration loaded later will be overwritten. The order of loading in the front, and only the order of loading in the back takes effect.
Conventional configuration->Application configuration->Mode configuration->Debug configuration->State configuration->Module configuration->Extended configuration->Dynamic configuration
Above The order is the ThinkPHP configuration loading order, and under normal circumstances, these configurations are automatically loaded. What we most often operate is application configuration, which is in the Application/Common/Conf/config.php file by default. During development, we can set our own configuration here. If you are not familiar with what values you can configure, you can open the ThinkPHP/Conf/convention.php file to view the corresponding configuration items
Reading configuration
During the development process, we sometimes need to read the configuration value of the application. In ThinkPHP, C ('configuration parameter name') is used to read the configuration. For example:
$model = C('URL_MODEL');
or
$model = C('url_model');
are equivalent. It is possible to read the setting value of the system's URL access mode, because the configuration items in ThinkPHP are not case-sensitive. However, it is recommended to use uppercase letters uniformly.
You can use the first letter of config to remember the C() method.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
MAMP installation and configuration PHP development environment in Mac OSX environment
The above is the detailed content of ThinkPHP installation and setup. For more information, please follow other related articles on the PHP Chinese website!