zoukankan      html  css  js  c++  java
  • ThinkPHP的运行流程-2

    Thinkphp为了提高编译的效率,第一次运行的时候thinkphp会把文件全部编译到temp目录下的~runtime.php文件,在第二次运行的时候会直接读取这个文件。所以我们在线下自己写代码测试的时候如果没有开启了这个调试模式的话,那么就没办法得到及时的反应。所以我们要将其开启。

    直接在index.php中添加如下代码即可开启:

    Define(‘APP_DEBUG’,TRUE);

    访问:http://127.0.0.1/

    其实是访问了http://127.0.0.1/index.php/index/index# 第一个index称之为模块,后面的index称之为方法

    第一个index.php顾名思义是文件

    第二个index是访问了LibAction目录下的index方法

    比如换一个:http://127.0.0.1/index.php/index/add

    则是访问了index下的add方法。

    该案例完整代码如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <?php
    // 本类由系统自动生成,仅供测试用途
    class IndexAction extends Action {
        public function index(){
        echo "劝君珍惜少年时,劝君莫惜金缕衣!";
        }
        public function del(){
            echo "this is index of del";
        }
        public function add(){
            echo "this is del of add";
        }
    }

    但是倘若我是这样的代码:

    1
    2
    3
    4
    5
    6
    7
    <?php
    // 本类由系统自动生成,仅供测试用途
    class IndexAction extends Action {
        public function test(){
            echo "我叫:{$_GET['name']},我今年{$_GET['age']}岁。";
        }
    }

    那么该如何访问呢?

    答案:http://127.0.0.1/index.php/index/test/name/张三/age/10

    依旧以变量然后斜杠然后再是值。所以很多时候sql注入的时候我们需要对那部分是key那部分是value区分清除。

    $this->display输出法。

     现在将代码换成

     

    然后我们访问的时候就会出现这样的效果:http://127.0.0.1/index.php/Index/test

    :(
    无法加载模块:test
    错误位置
    FILE: D:wampwww hinkphpCommonfunctions.php  LINE: 112

    PS:APP_DEBUG要开启。否则无法做到实时,就不会显示出了。

    显示是没办法加载模块的

    然后访问:http://127.0.0.1/index.php/Index/test  Index首字母是大写!然后显示是:

    :(
    模板不存在[./index/Tpl/Index/test.html]
    错误位置
    FILE: D:wampwww hinkphpLibCoreView.class.php  LINE: 115

    这时候就需要用到一个视图的了也就是MVC框架中的View了。

    然后访问Tpl目录。下面是没有任何文件夹的,我们建立一个Index文件夹。需要首字母大写!

    然后建立一个test.html的html文件,这里的test文件名也就是下图中方法的方法名。也就是说你定义的方法名就是你的文件名。

    PS:html代码如下

    1
    2
    3
    4
    5
    6
    <html>
    <head><title>test</title></head>
    <body>
    <h1>Con</h1>
    </body>
    </html>

    然后访问:http://127.0.0.1/index.php/Index/test的时候就可以了。

    这就是通过$this来实现视图效果。

  • 相关阅读:
    SpringBoot 如何生成接口文档,老鸟们都这么玩的!
    ELK 外网访问
    Elasticsearch 7.x配置用户名密码访问 开启x-pack验证
    在centos7 中安装Kibana
    在centos7 安装Elasticsearch 步骤:
    cuda-pytorch-gpu快速配置
    Face 2 to 3 D
    PointNet++
    PointNet:Deep Learning on Point Sets for 3D Classification and Segmentation
    3D Face Modeling From Diverse Raw Scan Data
  • 原文地址:https://www.cnblogs.com/nul1/p/9432094.html
Copyright © 2011-2022 走看看