zoukankan      html  css  js  c++  java
  • thinkphp学习笔记

    最简单的一个程序Hello World 参考ThinkPHP2.2 Example。

    自动生成Module Index, Index中有两个Action, index, checkEnv。

    checkEnv是一个探针,返回web服务器信息和php应用的信息。

    public function checkEnv() {

      load('pointer', THINK_PATH.'/Tpl/Autoindex');

      $env_table = check_env();

      echo $env_table;

    }

    load就是肯定就是装载文件的了,这没问题。怎么载入的require, include 不能满足吗?

    是的,首先load是公共函数,那么依照ThinkPHP的目录结构,load在ThinkPHP/Common/目录下,可能的文件是

    functions.php或者extends.php

    grep -r load ./ load的定义的确实在functions.php中。

    function load($name, $baseUrl = '', $ext = '.php') {

      $name = str_replace(array('.', '#'), array('/', '.'), $name); //也就是说我们加载的文件包含目录时,可以写成 example.func#class => example/func.class

      if(empty($baseUrl)) {

          if(0 === strpos($name, '@/')) { // @.example.func#class

               $baseUrl = APP_PATH . '/Common/'; //在应用Common中查找

               $name = substr($name, 2); // @.example.func#class => APP_PATH/Common/example/func.clas.php

          } else {

              $baseUrl = THINK_PATH.'/Common/'; //example.func#class => THINK_PHP/Common/example/func.class.php

        }

        if(substr($baseUrl, -1) != '/')    //这个函数是可以加载非Common中函数的哦

             $baseUrl .= '/';  //给没有目录末尾的路径添加 /

         require_cache($baseUrl.$name.$ext); // 这个是神马啊,不是require, require_once, include , include_one, 自定义的

    }

    在文件中查找 require_cache

    function require_cache($filename) {

       static $_importFiles = array();

       $filename = realpath($filename); //找出真实路径

       if(!isset($_importFiles[$filename])) { //查看是否已经加载过了

           if(file_exists_case($filename)) {   //只有没有加载过,并且文件存在的情况才加载

                  require $filename;

                  $_importFiles[$filename] = true;

            } else {  //文件不存在的情况

                    $_importFiles[$filename] = false;

            }

            return $_importFiles[$filename];

        }

    }

  • 相关阅读:
    Spring事务深入剖析--spring事务失效的原因
    CentOS 安装 VMware Tools 详细方法
    -手写Spring注解版本&事务传播行为
    手写spring事务框架-蚂蚁课堂
    springMvc接口开发--对访问的restful api接口进行拦截实现功能扩展
    spring框架中JDK和CGLIB动态代理区别
    mysql事务的坑----MyISAM表类型不支持事务操作
    git 远程分支和tag标签的操作
    git fetch和git pull的区别
    umask 文件默认权限
  • 原文地址:https://www.cnblogs.com/jesseZh/p/3040810.html
Copyright © 2011-2022 走看看