Home >Backend Development >PHP Tutorial >ThinkPHP installation and setup

ThinkPHP installation and setup

不言
不言Original
2018-06-07 17:20:492168browse

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(
  &#39;URL_ROUTER_ON&#39;  => true,
  &#39;URL_ROUTE_RULES&#39;=>array(

  &#39;blogs/:id&#39;        => array(&#39;Index/read&#39;),
  &#39;article/:id&#39;        => array(&#39;Article/show&#39;)
),
  &#39;URL_MAP_RULES&#39;=>array(
  &#39;new/top&#39; => &#39;Index/top?type=top&#39;
),

  &#39;DB_TYPE&#39;        => &#39;mysql&#39;,
  &#39;DB_HOST&#39;        => &#39;localhost&#39;,
  &#39;DB_NAME&#39;        => &#39;thinkdatabase&#39;,
  &#39;DB_USER&#39;        => &#39;root&#39;,
  &#39;DB_PWD&#39;        => &#39;password&#39;,
  &#39;DB_PORT&#39;        => &#39;3306&#39;,
  &#39;DB_PREFIX&#39;       => &#39;think_&#39;,

);

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(
  &#39;USER_CONFIG&#39;    => array(
    &#39;USER_AUTH&#39; => true,
    &#39;USER_TYPE&#39; => 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(&#39;URL_MODEL&#39;);

or

$model = C(&#39;URL_MODEL&#39;);

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn