zoukankan      html  css  js  c++  java
  • ThinkPHP笔记

    项目目录结构

    ├─index.php     项目入口文件
    ├─Common 项目公共文件目录
    ├─Conf 项目配置目录
    ├─Lang 项目语言目录
    ├─Lib 项目类库目录
    │  ├─Action Action类库目录
    │  ├─Behavior 行为类库目录
    │  ├─Model 模型类库目录
    │  └─Widget Widget类库目录
    ├─Runtime 项目运行时目录
    │  ├─Cache 模板缓存目录
    │  ├─Data 数据缓存目录
    │  ├─Logs 日志文件目录
    │  └─Temp 临时缓存目录
    └─Tpl 项目模板目录

    一. index.php入口文件:

    <?php
    define('APP_DEBUG',TRUE); // 开启调试模式
    require '/ThinkPHP框架所在目录/ThinkPHP.php';

    二. controller层:

    例如:Lib/Action/IndexAction.class.php

    <?php
    
    class IndexAction extends Action {
        public function index(){
            echo 'hello,world!';
        }
    }

    三.  URL请求

    ThinkPHP支持的URL模式有四种:普通模式、PATHINFO、REWRITE和兼容模式。

    普通模式

      也就是传统的GET传参方式来指定当前访问的模块和操作,例如:

      http://localhost/app/?m=module&a=action&var=value

    m参数表示模块,a操作表示操作(模块和操作的URL参数名称是可以配置的),后面的表示其他GET参数。

    PATHINFO模式

      是系统的默认URL模式,提供了最好的SEO支持,系统内部已经做了环境的兼容处理,所以能够支持大多数的主机环境。对应上面的URL模式,PATHINFO模式下面的URL访问地址是:

      http://localhost/app/index.php/module/action/var/value/

      PATHINFO地址的第一个参数表示模块,第二个参数表示操作。
      PATHINFO模式下面,URL是可定制的,例如,通过下面的配置:
    'URL_PATHINFO_DEPR'=>'-', // 更改PATHINFO参数分隔符

      我们还可以支持下面的URL访问:http://localhost/app/index.php/module-action-var-value/

    REWRITE模式

      是在PATHINFO模式的基础上添加了重写规则的支持,可以去掉URL地址里面的入口文件index.php,但是需要额外配置WEB服务器的重写规则。
    如果是Apache则需要在入口文件的同级添加.htaccess文件,内容如下:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </IfModule>

      接下来,就可以用下面的URL地址访问了:http://localhost/app/module/action/var/value/

    兼容模式

      是用于不支持PATHINFO的特殊环境,URL地址是:

      http://localhost/app/?s=/module/action/var/value/

      兼容模式配合Web服务器重写规则的定义,可以达到和REWRITE模式一样的URL效果。

     四、视图

    Tpl/模块名/操作名.html,例如:Tpl/Index/index.html

    <html>
     <head>
       <title>hello {$name}</title>
     </head>
     <body>
        hello, {$name}!
     </body>
    </html>
    class IndexAction extends Action {
        public function index(){ 
            $this->name = 'thinkphp'; // 进行模板变量赋值
            $this->display();
        }
    }
  • 相关阅读:
    LeetCode 81 Search in Rotated Sorted Array II(循环有序数组中的查找问题)
    LeetCode 80 Remove Duplicates from Sorted Array II(移除数组中出现两次以上的元素)
    LeetCode 79 Word Search(单词查找)
    LeetCode 78 Subsets (所有子集)
    LeetCode 77 Combinations(排列组合)
    LeetCode 50 Pow(x, n) (实现幂运算)
    LeetCode 49 Group Anagrams(字符串分组)
    LeetCode 48 Rotate Image(2D图像旋转问题)
    LeetCode 47 Permutations II(全排列)
    LeetCode 46 Permutations(全排列问题)
  • 原文地址:https://www.cnblogs.com/langtao/p/3120545.html
Copyright © 2011-2022 走看看