您的位置:首页 > 编程语言 > PHP开发

第一节Thinkphp3.2.3基础

2018-03-17 11:44 288 查看
1.目录结构
        index.php  入口文件
        Application  应用目录
        Public      资源文件目录
        ThinkPhP   框架目录
       当我们第一次访问入口文件时,系统自动会生成公共模块Common,默认模块home和Runtime目录
2.添加新的模块可以使用BIND_MODULE,例如想要添加admin模块,我们可以使用define('BIND_MODULE','Admin')。
3.如果更改应用目录,使用APP_PATH来改变
4.开启调试模式:define('APP_DEBUG',true),关闭则是false
5.控制器类的命名规范是:

  控制器名+Controller.class.php(模块名采用驼峰法并且首字母大写)。
6.操作方法是protected或者private类型的话,是无法直接通过URL访问。
7.视图:
      在view\index下创建hello.html:
     <html>
     <head>
      <title>hello    {$name}</title>
      </head>
       <body>
                hello,    {$name}!
      </body>
       </html>

      我们在home\Controller\IndexContrpller.class.php中添加hello方法:
        <?php
        namespace    Home\Controller;
        use Think\Controller;
        class IndexController    extends    Controller    {
                public    function    hello($name='thinkphp'){

                                $this->assign('name',$name);
                                $this->display();//默认去找view\index\hello.html
                  }
        }

           我们在浏览器访问输出:hello,thinkphp!
   8.读取数据

            我们在Index控制器加一个index方法:
            public    function    index(){
                                $Data =M('Data');//    实例化Data数据模型
                                $result = $Data->find(1);
                                $this->assign('result',$result);

                                $this->display()
             }
             然后我们在模板文件写入:
                       <html>
                        <head>
                        <title></title>
                        </head>
                         <body>
                          {$result.id}--{$result.data}

                         </body>
                          </html>
           我们访问会输出第一条的记录内容。

      
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  thinkphp