Home Backend Development PHP Tutorial ThinkPHP installation and setup

ThinkPHP installation and setup

Jun 07, 2018 pm 05:20 PM
thinkphp Installation configuration

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;,

);
Copy after login

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,
  ),
);
Copy after login

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;);
Copy after login
Copy after login

or

$model = C(&#39;URL_MODEL&#39;);
Copy after login
Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

Getting Started with Pygame: Comprehensive Installation and Configuration Tutorial Getting Started with Pygame: Comprehensive Installation and Configuration Tutorial Feb 19, 2024 pm 10:10 PM

Learn Pygame from scratch: complete installation and configuration tutorial, specific code examples required Introduction: Pygame is an open source game development library developed using the Python programming language. It provides a wealth of functions and tools, allowing developers to easily create a variety of type of game. This article will help you learn Pygame from scratch, and provide a complete installation and configuration tutorial, as well as specific code examples to get you started quickly. Part One: Installing Python and Pygame First, make sure you have

Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Nov 22, 2023 pm 12:01 PM

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

How is the performance of thinkphp? How is the performance of thinkphp? Apr 09, 2024 pm 05:24 PM

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

See all articles