美文网首页
ThinkPHP基础-----第一章

ThinkPHP基础-----第一章

作者: 大菜鸟呀 | 来源:发表于2018-08-22 15:33 被阅读5次

    1、thinkPHP 5.0基本目录:

    目录结构:
        |———application     应用目录->整个网站的核心
            |——index        前台目录
                |——controller   控制器
                |——model        数据模型
                |——view         页面
            |——admin        后台目录
        |———extend          扩展类库目录
        |———public          静态资源和入口文件
            |——static       存放静态资源(css、js、img)
            |——index.php    入口文件
        |———runtime         网站运行临时目录
        |———tests           测试目录
        |———thinkphp        thinkphp核心文件
            |——lang         语言包
            |——library      TP 核心文件
            |——tpl          模板页面
        |———vendor          第三方扩展目录
    

    2、URL地址:

        访问www.tp.com 相当于访问:
        http://www.tp.com/ index.php /index /index /index
                域名      /   入口文件    /前台目录/控制器/方法
    

    3、开发模式

      1、连接数据库(tp5/application/database.php)
            return [
            // 数据库类型
            'type'            => 'mysql',
            // 服务器地址
            'hostname'        => '127.0.0.1',
            // 数据库名
            'database'        => 'tp5',
            // 用户名
            'username'        => 'root',
            // 密码
            'password'        => ''
            ]
    
     2、开启调试模式(tp5/application/config.php)
            // 应用调试模式
            'app_debug'       => true
    
         3、配置index.php
    \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 '这是我的第一个ThinkPHP';
            //从数据库中读取数据
            $data=Db::table("user")->select();
            //var_dump($data);
    
            //分配数据给页面
            $this->assign('data',$data);
            //加载页面
            return view();
        }
    }
    
    
    4、在\tp5\application\index\ 下新建view文件夹
    在view文件夹下新建index文件夹
    在index文件夹下新建index.php文件
    index.php:
    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    </head>
    <body>
        <table border="1" width="800px" align="center">
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Password</th>
            </tr>
        {volist name="data" id="value"}
            <tr>
                <th>{$value.id}</th>
                <th>{$value.name}</th>
                <th>{$value.password}</th>
            </tr>
        {/volist}
        </table>
    </body>
    </html>
    

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

    相关文章

      网友评论

          本文标题:ThinkPHP基础-----第一章

          本文链接:https://www.haomeiwen.com/subject/dalyiftx.html