thinkphp目录结构

目录结构

  • application 应用目录(可设置)是整个网站的核心
    ———index前台目录
    ————————controller控制器
    ————————model数据模型
    ————————view页面
    ———admin后台目录
  • extend 扩展类库资源
  • public静态资源和入口文件
    ——static 存放静态资源css、js、img、
    ——index.php 入口文件
  • runtime 网站运行临时目录
  • thinkphp 框架的核心文件
    ——lang
    ——library TP核心文件
    ——tpl模板页面
  • vendor 第三方扩展

url地址的了解

http://localhost/tp5/public    /index.php    /Index     /Index    /index
——                             入口文件       前台       控制器     方法

了解TP开发模式

1、连接数据库(C:\AppServ\www\tp5\application\database.php)

'type'            => 'mysql',
    // 服务器地址
    'hostname'        => '127.0.0.1',
    // 数据库名
    'database'        => 'yzm',
    // 用户名
    'username'        => 'root',
    // 密码
    'password'        => '数据库的密码',

2、控制器中的代码(C:\AppServ\www\tp5\application\index\controller\index.php)

<?php
namespace app\index\controller;

//引入系统数据库类
use think\Db;
//引入系统控制器类
use think\Controller;

class Index extends Controller
{
    public function index()
    {
       //return "耘哥真帅";

        //从数据库中读取数据
        $data = Db::table('user')->select();
        //分配数据给页面
        $this->assign('data',$data);

        //加载页面
        return view();

        /*var_dump($data);*/

    }
}

3、页面中(C:\AppServ\www\tp5\application\index\view\index\index.html)

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<h1>我哈哈哈哈哈哈哈</h1>
<table border="=1"width="800px" align="center">
    <tr>
        <th>ID</th>
        <th>NAME</th>
        <th>PASS</th>
    </tr>
    <!--循环输出表格内容-->
    {volist name="data" id="value"}
    <tr>
        <td>{$value.id}</td>
        <td>{$value.name}</td>
        <td>{$value.pass}</td>
    </tr>
    {/volist}

</table>
</body>
</html>

MVC模式

m model模型
v view视图
c controller控制器

  • 生活中的MVC:
11058807-0399eb24c08088ac.png
image.png
  • 程序中的MVC:


    11058807-3b12e776822469c9.png
    程序中的mvc.png

MVC在TP中如何体现

1、M model模型
C:\AppServ\www\tp5\application\index\model
作用:执行数据库相关处理
2、V view视图
C:\AppServ\www\tp5\application\index\view
作用:其实就是页面
3、C Controller控制器
C:\AppServ\www\tp5\application\index\controller
作用:主要控制了逻辑的运转

MVC变形
1、MC模型和控制器
主要作用:用于接口开发
2、VC视图和控制器
主要作用:单页面的网站

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值