Home > Article > Backend Development > Introduction to ThinkPHP5 quick start method
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 命令行工具入口
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 框架引导文件
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
and then on the browser side Enter: http://localhost/tp5/public/
You will see the welcome page:
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
You can then directly access
http://localhost:8888##Introduction to ThinkPHP5 quick start method. Directory structure
├─application 应用目录(可设置) │ ├─index 模块目录(可更改) │ │ ├─config.php 模块配置文件 │ │ ├─common.php 模块公共文件 │ │ ├─controller 控制器目录 │ │ ├─model 模型目录 │ │ └─view 视图目录 │ │ │ ├─command.php 命令行工具配置文件 │ ├─common.php 应用公共文件 │ ├─config.php 应用配置文件 │ ├─tags.php 应用行为扩展定义文件 │ ├─database.php 数据库配置文件 │ └─route.php 路由配置文件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 demowill generate a default demo module, including the following directory structure:
├─demo │ ├─controller 控制器目录 │ ├─model 模型目录 │ ├─view 视图目录 │ ├─config.php 模块配置文件 │ └─common.php 模块公共文件 同时也会生成一个默认的 Index 控制器文件。4. Template rendering
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;; } }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(); } }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>Then we can access:
http://localhost/tp5/public/
More advanced ones can configure URL routing.
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;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,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(); } }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>Then visit
http://localhost/tp5/public/index.php/index/index/dbtest.
Introduction to the steps for using ThinkPHP
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!