目录结构与MVC模式
目录结构
application
- 应用目录,整个网站的核心
- 前台:index
- controller控制器
- model数据模型
- view页面
- 后台:admin
extend
- 扩展类库目录:引入别的类库
public
- static:存放静态资源
- index.php入口文件
runtime
- 网站运行临时目录
tests
- 测试目录
thinkphp
- tp框架核心文件
lang
- 语言包
library
- TP核心文件
tpl
- 模板页面
vendor
- 第三方扩展目录
URL地址了解
http:// www.tp.com / index.php / Index / Index / index
域名 入口文件 前台(index文件夹) 前台控制器(controller) 方法
也就是调用index下的controller的index.php的index方法
tp开发模式
1.连接数据库
修改application\database.php文件为当前配置信息
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'database' => 'tptest',
// 用户名
'username' => 'tptest',
// 密码
'password' => '123456',
2.从数据库中读取数据
控制器中书写代码
index.php
<?php
namespace app\index\controller;
//引用系统控制器类
use think\Controller;
//引用系统数据库类
use think\Db;
class Index