Home  >  Article  >  Backend Development  >  ThinkPHP study notes (1) ThinkPHP deployment_PHP tutorial

ThinkPHP study notes (1) ThinkPHP deployment_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:24:10919browse

已经下载了wampserver,以后有时间试下在本地运行ThinkPHP。

在app/lib/Action/文件夹下可以为每一个模块定义控制器类,一个模块可以包含多个操作方法,当有请求的时候,会从URL参数中解析当前请求的模块和操作。比如定义的默认控制器类IndexAciton.class.php:

<&#63;php
class IndexAction extends Action{
  ptotect function _initialize(){
    header("Content-Type:text/html;charset=utf-8");
  }
  public function index(){
    $this->display();
  }
  public function imit(){
    echo "<h2>Sae服务模拟器功能测试(以下服务在本地也可以运行):</h2>";
  }
}

访问http://localhost/,系统会访问默认的模块(Index)的默认操作(index)。相对的输入http://localhost/Index/imit,系统就会访问默认的模块(Index)的操作方法(imit)。这种URL模式是PATHINFO模式,ThinkPHP的默认格式,还可以在ThinkPHP/Conf/convention.php里设置其他格式,如普通模式、REWRITE模式和兼容模式。

只是笔记,为什么不能设置为仅自己可见呢,我写的乱七八糟都不好意思给人看啊。

URL请求的REWRITE模式,是在PATHINFO模式的基础上添加重写规则的支持,Apache的话,是在入口文件同级处添加.htaccess文件,内容是:

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

只有这样是不行的,还需要开启Apache的rewrite功能。在httpd.conf配置文件中找到LoadModule rewrite_module modules/mod_rewrite.so去掉前面的#,找到AllowOverride None改为AllowOverride All。如此才有效。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/825530.htmlTechArticle已经下载了wampserver,以后有时间试下在本地运行ThinkPHP。 在app/lib/Action/文件夹下可以为每一个模块定义控制器类,一个模块可以包含多个操...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn