ThinkPHP 常用配置 和 四种url访问方式

本文详细介绍了ThinkPHP框架中与数据库连接相关的配置,包括如何改变左右定界符,以及支持的四种URL模式:普通模式、pathinfo模式、rewrite模式和兼容模式。同时解释了如何修改Apache配置文件以支持rewrite地址重写。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

改变左右定界符:
ThinkPHP/Conf/convention.php
'TMPL_L_DELIM' => '<{',

'TMPL_R_DELIM' => '}>',


与数据库连接有关的配置:
ThinkPHP/Conf/convention.php
'DB_TYPE' => 'mysql',
'DB_HOST' => 'localhost'
'DB_NAME' => 'test',
'DB_USER' => 'root',
'DB_PWD' => '123',
'DB_PORT' => '3306',
注:这个配置文件会被所有的 TP 项目共享使用

ThinkPHP  支持四种 URL  模式:
1.普通模式
http://localhost/test/index.php?m=Index&a=index&id=10
获取模块和方法名称:
MODULE_NAME
ACTION_NAME
2.pathinfo 模式
http://localhost/test/index.php/Index/index/id/10
3.rewrite 模式
http://localhost/test/Index/index/id/10
注:修改 apache 配置文件时:
1)LoadModule rewrite_module modules/mod_rewrite.so
2)修改网站根目录支持 rewrite 地址重写
<Directory "C:/AppServ/www">
Options Indexes FollowSymLinks
#一定要把 multiviews 取掉
AllowOverride All
Order allow,deny
Allow from all
</Directory>
3)重启 apache
4)把.htaccess 放到入口文件目录下:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

4.兼容模式
http://localhost/test/?s=/Index/index/id/10
默认访问模块和方法:
convention.php:
'DEFAULT_MODULE' => 'Index', // 默认模块名称
'DEFAULT_ACTION' => 'index', // 默认操作名称


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值