ThinkPHP学习手记环境搭建,thinkphp手记搭建
ThinkPHP学习手记——环境搭建,thinkphp手记搭建
怀着激动的心情打开了thinkPHP的文档,开启了第一次php框架学习。
下载
ThinkPHP最新版本可以在官方网站(http://thinkphp.cn/down/framework.html)
或者Github(https://github.com/liu21st/thinkphp/downloads)下载。
把下载后的压缩文件解压到你的WEB目录(或者任何目录都可以)
建议下载完整版,这可以再配置期间免去很多莫名其妙的麻烦
入口文件
下面附上官网的内容
在开始之前,你需要一个Web服务器和PHP运行环境,如果你暂时还没有,我们推荐使用集成开发环境WAMPServer(是一个集成了Apache、PHP和MySQL的开发套件,而且支持多个PHP版本、MySQL版本和Apache版本的切换)来使用ThinkPHP进行本地开发和测试。
接下来我们先在WEB根目录下面创建一个app子目录(这个app就是我们的项目名),然后在该目录下面创建一个index.php文件,添加一行简单的代码:
require '/ThinkPHP框架所在目录/ThinkPHP.php';
其实这个index.php无需自己创建,在下载包中已经是有的了。
单一项目
我们就可以直接通过http://localhost/访问项目了。
多项目
如果想创建多个项目,你也可以在Web根目录下面创建多个子目录来部署多个项目。每个项目目录里包含一个入口文件。
创建project1文件夹
创建并打开入口文件(index.php)
加入如下代码
define('APP_DEBUG',true); //开启调试模式
require('../ThinkPHP/ThinkPHP.php');
?>
在浏览器打开 http://localhost/project1/,便可以看到thinkphp的欢迎页面了。
ThinkPHP运行流程
浏览器访问 入口文件的时候 时,发生了什么?think的执行流程是怎么样的?
(1)第一步:引入框架下的 thinkphp.php
thinkphp.php文件,定义了常量app_name和think_path(大写),并引入runtime.php
(2)第二步,加载框架下的 Common/runtime.php文件
- 再次定义了一些常量,具体见源码;
- 创建项目目录结构,由build_app_dir()方法创建;
- 如果app_dubug设置为false,则把核心加载文件进行编译。否则,删除编译文件,即项目下的~runtime.php文件;
- 调用框架ThinkPHP下的 lib/core/Think.class.php 文件——>执行入口 Think::Start()。
(3)第三步,执行框架ThinkPHP下的 lib/core/Think.class.php 的start()方法
- 接第二步,开始执行入口文件Think::Start()。包括声明错误处理句柄、异常处理句柄,并声明类的自动加载机制;
- Think::buildApp(); //初始化app运行,即项目预编译,加载项目的各种配置文件,大约有10个文件左右。
- 加载完配置文件后,执行app::run
(4)第四步,执行框架下的 lib/core/App.class.php下的run方法
- 执行app下init()静态方法:分析url,得出调用哪个控制器。
- 执行app下exec静态方法:根据计算出来的模型和方法,实例化该module,并执行action相应的方法。本实例找到的项目下 lib/action目录下的 IndexAction.class.php,并执行index()方法。
经过了以上这么多的步骤,我们终于是看到了浏览器上显示的 thinkphp欢迎页面。
网站分享
官网:
http://www.thinkphp.cn/
API:
http://doc.thinkphp.cn/
论坛:
http://www.ithinkphp.com/
可以不需要,安装集成包吧,比如xampp,appserver,phpnow等
方法不能自动定位是啥意思

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
