thinkphp目录结构

2018-04-23  本文已影响0人  kangshuaibo

目录结构

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控制器

image.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视图和控制器
主要作用:单页面的网站

上一篇 下一篇

猜你喜欢

热点阅读