ThinkPHP__安装与使用

安装(tp 5.1)

composer create-project topthink/think=5.1.36
在这里插入图片描述

简单使用
查询学生表的名称

sql

CREATE TABLE `student` (
	`id` INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
	`name` VARCHAR(10) NOT NULL UNIQUE DEFAULT '',
	`gender` TINYINT UNSIGNED NOT NULL DEFAULT 0,
	`email` VARCHAR(128) NOT NULL DEFAULT '',
	`mobile` VARCHAR(20) NOT NULL DEFAULT '',
	`entry_date` DATE NOT NULL
) ENGINE=INNODB DEFAULT CHARSET=utf8;


INSERT INTO `student` VALUES
(1, 'Allen4', 0, 'a@qq.com', '1231233123', '2019-01-03'),
(2, 'Allen1', 1, 'b@qq.com', '1231243123', '2019-01-03'),
(3, 'Allen2', 1, 'c@qq.com', '1231235123', '2019-01-04'),
(4, 'Allen3', 0, 'd@qq.com', '1231236123', '2019-01-03');

修改tp5 数据库配置文件
/config/database.php
在这里插入图片描述

逻辑代码:\application\index\controller\Index.php

    public function student() {
//        $student = \think\Db::query('SELECT `name` FROM `student`');

        $student = \think\Db::name('student')->field('name')->select();
        $this->assign('data', $student);
        return $this->fetch();
    }

模板文件: \application\index\view\index\student.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生列表</title>
</head>
<body>
    {foreach $data as $v}
    {$v.name}<br/>
    {/foreach}
</body>
</html>

访问:http://127.0.0.1:8082/index.php/index/index/student
在这里插入图片描述

打开调试模式 :

\config\app.php
在这里插入图片描述
在访问时页面下方有调试信息
在这里插入图片描述

apache配置
<VirtualHost *:80>
    ##ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "G:\web\wamp\www\think\public"
    ##ServerName dummy-host2.example.com
    ErrorLog "logs/tp-error.log"
    CustomLog "logs/tp-access.log" common
	<Directory "G:\web\wamp\www\think\public">
		#
		# Possible values for the Options directive are "None", "All",
		# or any combination of:
		#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
		#
		# Note that "MultiViews" must be named *explicitly* --- "Options All"
		# doesn't give it to you.
		#
		# The Options directive is both complicated and important.  Please see
		# http://httpd.apache.org/docs/2.4/mod/core.html#options
		# for more information.
		#
		Options +FollowSymLinks -MultiViews

		#
		# AllowOverride controls what directives may be placed in .htaccess files.
		# It can be "All", "None", or any combination of the keywords:
		#   AllowOverride FileInfo AuthConfig Limit
		#
		AllowOverride All

		#
		# Controls who can get stuff from this server.
		#
		<IfModule rewrite_module>
			Require all granted
			RewriteEngine On
			RewriteCond %{REQUEST_FILENAME} !-d
			RewriteCond %{REQUEST_FILENAME} !-f
			RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
		</IfModule>
	</Directory>
</VirtualHost>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值