Home Backend Development PHP Tutorial Introduction to ThinkPHP5 quick start method

Introduction to ThinkPHP5 quick start method

Jun 15, 2018 am 10:28 AM
github thinkphp5

Introduction to ThinkPHP5 quick start method. Download

Download address: http://www.thinkphp.cn/
This time using thinkphp5, I used github to install it.

Github
Application project: https://github.com/top-think/think
Core framework: https://github.com/top-think/framework

In addition:
Code Cloud:
Application project: https://git.oschina.net/liuIntroduction to ThinkPHP5 quick start methodIntroduction to ThinkPHP5 quick start methodst/thinkphp5.git
Core framework: https://git.oschina.net/liuIntroduction to ThinkPHP5 quick start methodIntroduction to ThinkPHP5 quick start methodst/ framework.git
Coding:
Application project: https://git.coding.net/liuIntroduction to ThinkPHP5 quick start methodIntroduction to ThinkPHP5 quick start methodst/thinkphp5.git
Core framework: https://git.coding.net/liuIntroduction to ThinkPHP5 quick start methodIntroduction to ThinkPHP5 quick start methodst/framework.git

Downloaded directory:

 tp5 
├─application                   应用目录 
├─extend                                        扩展类库目录(可定义) 
├─public                                        网站对外访问目录 
├─runtime                                   运行时目录(可定义) 
├─vendor                                        第三方类库目录(Composer) 
├─thinkphp                              框架核心目录 
├─build.php                         自动生成定义文件(参考) 
├─composer.json         Composer定义文件 
├─LICENSE.txt                   授权说明文件 
├─README.md                         README  文件 
├─think                                         命令行工具入口
Copy after login

The structure of the core framework directory is as follows:

├─thinkphp  框架系统目录 
│       ├─lang                                                          语言包目录 
│       ├─library                                               框架核心类库目录 
│       │       ├─think                                         think   类库包目录 
│       │       └─traits                                        系统  traits  目录 
│       ├─tpl                                                               系统模板目录 
│       │ 
│       ├─.htaccess                                     用于  apache  的重写 
│       ├─.travis.yml                               CI  定义文件 
│       ├─base.php                                          框架基础文件 
│       ├─composer.json                     composer    定义文件 
│       ├─console.php                               控制台入口文件 
│       ├─convention.php                    惯例配置文件 
│       ├─helper.php                                    助手函数文件(可选) 
│       ├─LICENSE.txt                               授权说明文件 
│       ├─phpunit.xml                               单元测试配置文件 
│       ├─README.md                                     README  文件 
│       └─start.php                                     框架引导文件
Copy after login
Introduction to ThinkPHP5 quick start method. Run

I use It is the apacheIntroduction to ThinkPHP5 quick start method server that comes with kali. Use service apacheIntroduction to ThinkPHP5 quick start method start to start. You need to put the entire project downloaded from git into the server running directory. The default for Linux is:

/var/www/html
Copy after login

and then on the browser side Enter: http://localhost/tp5/public/
You will see the welcome page:

Introduction to ThinkPHP5 quick start method

If you don’t want to install any WEB server, you can also directly use the WebServer that comes with PHP and run router.php to run the test.
Enter the command line, enter the tp5/public directory, and enter the following command:

php -S  localhost:8888  router.php
Copy after login

You can then directly access

http://localhost:8888
Copy after login

Introduction to ThinkPHP5 quick start method

##Introduction to ThinkPHP5 quick start method. Directory structure What we pay most attention to is the application directory:

├─application                                           应用目录(可设置) 
│       ├─index                                                     模块目录(可更改) 
│       │       ├─config.php                        模块配置文件 
│       │       ├─common.php                        模块公共文件 
│       │       ├─controller                        控制器目录 
│       │       ├─model                                         模型目录 
│       │       └─view                                              视图目录 
│       │ 
│       ├─command.php                               命令行工具配置文件 
│       ├─common.php                                    应用公共文件 
│       ├─config.php                                    应用配置文件 
│       ├─tags.php                                          应用行为扩展定义文件 
│       ├─database.php                          数据库配置文件 
│       └─route.php                                     路由配置文件
Copy after login

The 5.0 version adopts a modular design architecture. There is only one index module directory under the default application directory. If you want to add a new module, you can use the control command to generate. Switch to the command line mode, enter the application root directory (under tp5) and execute the following instructions:

php think   build   --module    demo
Copy after login

will generate a default demo module, including the following directory structure:


├─demo 
│       ├─controller                        控制器目录 
│       ├─model                                         模型目录 
│       ├─view                                              视图目录 
│       ├─config.php                        模块配置文件 
│       └─common.php                        模块公共文件 
同时也会生成一个默认的 Index 控制器文件。
Copy after login

4. Template renderingFirst is the Controller:

Located at
application/index/controller/Index.php there is a default Index class: Originally it returned the start page, but now it returns hello world.

<?phpnamespace   app\index\controller;class Index{
        public function index()
        {
            return  &#Introduction to ThinkPHP5 quick start method9;Hello,World!&#Introduction to ThinkPHP5 quick start method9;;
        }
}
Copy after login

Then we inherit the Controller class:

<?phpnamespace app\index\controller;use think\Controller;//引入Controller类class Index extends Controller{
    public function index($name=&#Introduction to ThinkPHP5 quick start method9;world&#Introduction to ThinkPHP5 quick start method9;)
    {
        $this->assign(&#Introduction to ThinkPHP5 quick start method9;name&#Introduction to ThinkPHP5 quick start method9;,$name);        return $this->fetch();
    }
}
Copy after login

We pass a parameter name with a default value to the page.

Then View:

thinkphph uses template rendering. The template is stored in the View folder. There is no View folder by default. We create it ourselves:
Create a view directory under the
application/index directory, create an index directory under the view directory, and then add the template file hello.html, the entire path: view/index/hello.html

<html><head><title>hello {$name}</title></head><body>
    hello {$name}!</body></html>
Copy after login

Then we can access:


Introduction to ThinkPHP5 quick start method

or use the omitted path:

http://localhost/tp5/public/ More advanced ones can configure URL routing.

5. Access the databaseMysql database is used here, and a database is built under the test table:

create table if not exists think_data( id int(8) not null auto_increment primary key, data varchar(Introduction to ThinkPHP5 quick start method55) not null )engine=MyISAM default charset=utf8;
Copy after login

Just insert a few more pieces of data;

Then configure it under
application/database.php:

return [    // 数据库类型
    &#Introduction to ThinkPHP5 quick start method9;type&#Introduction to ThinkPHP5 quick start method9;           => &#Introduction to ThinkPHP5 quick start method9;mysql&#Introduction to ThinkPHP5 quick start method9;,    // 服务器地址
    &#Introduction to ThinkPHP5 quick start method9;hostname&#Introduction to ThinkPHP5 quick start method9;       => &#Introduction to ThinkPHP5 quick start method9;Introduction to ThinkPHP5 quick start methodIntroduction to ThinkPHP5 quick start method7.0.0.Introduction to ThinkPHP5 quick start method&#Introduction to ThinkPHP5 quick start method9;,    // 数据库名
    &#Introduction to ThinkPHP5 quick start method9;database&#Introduction to ThinkPHP5 quick start method9;       => &#Introduction to ThinkPHP5 quick start method9;test&#Introduction to ThinkPHP5 quick start method9;,    // 用户名
    &#Introduction to ThinkPHP5 quick start method9;username&#Introduction to ThinkPHP5 quick start method9;       => &#Introduction to ThinkPHP5 quick start method9;root&#Introduction to ThinkPHP5 quick start method9;,    // 密码
    &#Introduction to ThinkPHP5 quick start method9;password&#Introduction to ThinkPHP5 quick start method9;       => &#Introduction to ThinkPHP5 quick start method9;&#Introduction to ThinkPHP5 quick start method9;,    // 端口
    &#Introduction to ThinkPHP5 quick start method9;hostport&#Introduction to ThinkPHP5 quick start method9;       => &#Introduction to ThinkPHP5 quick start method9;&#Introduction to ThinkPHP5 quick start method9;,    // 连接dsn
    &#Introduction to ThinkPHP5 quick start method9;dsn&#Introduction to ThinkPHP5 quick start method9;            => &#Introduction to ThinkPHP5 quick start method9;&#Introduction to ThinkPHP5 quick start method9;,    // 数据库连接参数
    &#Introduction to ThinkPHP5 quick start method9;params&#Introduction to ThinkPHP5 quick start method9;         => [],    // 数据库编码默认采用utf8
    &#Introduction to ThinkPHP5 quick start method9;charset&#Introduction to ThinkPHP5 quick start method9;        => &#Introduction to ThinkPHP5 quick start method9;utf8&#Introduction to ThinkPHP5 quick start method9;,    // 数据库表前缀
    &#Introduction to ThinkPHP5 quick start method9;prefix&#Introduction to ThinkPHP5 quick start method9;         => &#Introduction to ThinkPHP5 quick start method9;think_&#Introduction to ThinkPHP5 quick start method9;,    // 数据库调试模式
    &#Introduction to ThinkPHP5 quick start method9;debug&#Introduction to ThinkPHP5 quick start method9;          => true,
Copy after login

Modify the Index class under the controller:

<?phpnamespace app\index\controller;use think\Controller;use think\Db;//引入数据库class Index extends Controller{
    public function index($name=&#Introduction to ThinkPHP5 quick start method9;world&#Introduction to ThinkPHP5 quick start method9;)
    {
        $this->assign(&#Introduction to ThinkPHP5 quick start method9;name&#Introduction to ThinkPHP5 quick start method9;,$name);        return $this->fetch();
    }    public function dbtest()
    {
        $data = Db::name(&#Introduction to ThinkPHP5 quick start method9;data&#Introduction to ThinkPHP5 quick start method9;)->find();        $this->assign(&#Introduction to ThinkPHP5 quick start method9;result&#Introduction to ThinkPHP5 quick start method9;,$data);        return $this->fetch();
    }
}
Copy after login

Then build a dbtest in the index directory under the view. HTML rendering:

<html><head><title></title></head><body>
    {$result.id---$result.data}</body></html>
Copy after login
Then visit

http://localhost/tp5/public/index.php/index/index/dbtest.

This article explains the quick start method of ThinkPHP5. For more related content, please pay attention to the php Chinese website.

Related recommendations:

Introduction to the steps for using ThinkPHP

Unlockable queries

Explain the relevant knowledge of update lock (U) and exclusive lock (X)

The above is the detailed content of Introduction to ThinkPHP5 quick start method. 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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

GitHub project sharing: 10 open source online games that can be played with just one click GitHub project sharing: 10 open source online games that can be played with just one click Mar 24, 2023 pm 07:15 PM

This article summarizes 10 open source online games on GitHub, which can be played by clicking on them. Most of the games can be played on mobile phones, which is really cool!

what is github what is github Mar 24, 2023 pm 05:46 PM

GitHub is a hosting platform for open source and private software projects, allowing developers to host their own code here and perform version control. GitHub focuses on open source projects and collaboration. Through open source projects on this platform, developers can view the source code of other developers' projects, communicate and learn.

[Summary] Some reasons and solutions that may cause GitHub to not open [Summary] Some reasons and solutions that may cause GitHub to not open Mar 27, 2023 am 11:33 AM

GitHub is a very popular version control and code hosting platform. However, sometimes we may encounter the problem of being unable to access GitHub. This is because GitHub is a global platform and is affected by factors such as geographical location, network conditions, and website settings. This article will introduce some possible reasons why GitHub cannot be opened, as well as methods to solve these problems.

How to download only the contents of one folder in github How to download only the contents of one folder in github Mar 27, 2023 am 10:53 AM

GitHub is a popular code hosting platform used for developer collaboration and version control. As a developer, you may need to download only the contents of a specific folder from another developer's GitHub repository. In this article, we will demonstrate how to download only a folder in a GitHub repository without downloading the entire repository.

Let's talk about how to delete a folder in the GitHub repository Let's talk about how to delete a folder in the GitHub repository Mar 27, 2023 am 11:33 AM

GitHub is a very popular version control system that allows users to store and share their code bases on the Internet. It is one of the must-have tools for programmers. However, sometimes we may need to delete a folder in the GitHub repository. This article will introduce how to delete a folder in the GitHub repository.

Let's talk about how to upload projects and text documents in github Let's talk about how to upload projects and text documents in github Mar 27, 2023 am 10:53 AM

GitHub is a Git-based code hosting platform that is widely used in open source communities and internal enterprise code management. You can upload projects and text documents on GitHub, but the formats it supports and the upload methods are slightly different.

How to install GitHub Copilot on Windows 11/10 How to install GitHub Copilot on Windows 11/10 Oct 21, 2023 pm 11:13 PM

GitHubCopilot is the next level for coders, with an AI-based model that successfully predicts and autocompletes your code. However, you might be wondering how to get this AI genius on your device so that your coding becomes even easier! However, using GitHub isn't exactly easy, and the initial setup process is a tricky one. Therefore, we created this step-by-step tutorial on how to install and implement GitHub Copilot in VSCode on Windows 11, 10. How to install GitHubCopilot on Windows There are several steps to this process. So, follow the steps below now. Step 1 – You must have the latest version of Visual Studio installed on your computer

Let's talk about how to set up a protected branch and submit a PR in Gitlab Let's talk about how to set up a protected branch and submit a PR in Gitlab Mar 30, 2023 pm 09:01 PM

This article is about learning Gitlab, talking about how to set up a protected branch and submit a PR to your leader. I hope it will be helpful to everyone!

See all articles