当前位置:网站首页>thinkphp3.2.3中设置路由,优化url
thinkphp3.2.3中设置路由,优化url
2022-07-07 14:06:00 【全栈程序员站长】
需求: 访问这个目录的时候,http://xx.com/p-412313要重定向到(暂且这么叫)http://xx.com/Home/Blog/index/id/412313
就是看着好看
我的应用目录是Application。模块是Home
第一步:知道哪个文件怎么处理的路由 路由处理在think/Route.class.php
- // 动态路由处理
- $routes = C(‘URL_ROUTE_RULES’);
- // var_dump($routes);
- if(!empty($routes)) {
- // dump($routes);
- //array(1) {
- // [“/^p-(\d+)$/”] => string(16) “Blog/index?id=:1”
- //}
- // echo “rount.class.php\n”;
- foreach (routes as rule=>
- if(is_numeric($rule)){
- // 支持 array(‘rule’,’adddress’,…) 定义路由
- rule = array_shift(route);
- }
- …代码多,仅标识位置
第二步:在项目模块的配置文件下,设置配置文件 如下(因为tp是逐级加载配置文件,惯例配置->应用配置->模式配
置->调试配置->状态配置->模块配置->扩展配置->动态配置,这里属于模块配置
- <?php
- return array(
- ‘MODULE_ALLOW_LIST’ => array(‘Home’,‘Admin’,‘Common’),
- ‘DEFAULT_MODULE’ => ‘Home’, // 默认模块
- ‘DEFAULT_CONTROLLER’ => ‘Index’, // 默认控制器名称
- ‘DEFAULT_ACTION’ => ‘index’, // 默认操作名称
- // 路由规则
- ‘URL_ROUTER_ON’ => TRUE,
- ‘URL_ROUTE_RULES’ => array(
- ‘/^c-(\d+)$/’ => ‘Index/content?id=:1’
- ),
- ‘URL_ROUTER_ON ‘=>true,
- ‘URL_MODEL’ => ‘1’,
- ‘URL_ROUTE_RULES’=>array(
- ‘/^p-(\d+)$/’ => ‘Home/Blog/index?id=:1’,//意思是访问x.com/p-34 会访问的是x.com/Blog/index/id/34
- ),
- );
第三部: 如果你没有设置默认的模块 ,会出现找不到p-34这个模块的错误。 那么需要在index.php中设置 define(‘BIND_MODULE’,’Home’);
这样就可以了。
说明:如果没有第三步。默认打开是正常的就是这样。
但是
所以我们操作第三步,就可以实现如下效果了:
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/113178.html原文链接:https://javaforall.cn
边栏推荐
- Unity drawing plug-in = = [support the update of the original atlas]
- Numpy -- data cleaning
- torch. Numel action
- Mesh merging under ue4/ue5 runtime
- leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
- Unity3d click events added to 3D objects in the scene
- Three. JS introduction learning notes 12: the model moves along any trajectory line
- 95.(cesium篇)cesium动态单体化-3D建筑物(楼栋)
- 统计学习方法——感知机
- C Alibaba cloud OSS file upload, download and other operations (unity is available)
猜你喜欢
10 schemes to ensure interface data security
Description of vs common shortcut keys
C4D learning notes 2- animation - timeline and time function
谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
山东老博会,2022中国智慧养老展会,智能化养老、适老科技展
MySQL数据库基本操作-DQL-基本查询
Continuous creation depends on it!
numpy--疫情数据分析案例
Unity3d click events added to 3D objects in the scene
Apache Doris刚“毕业”:为什么应关注这种SQL数据仓库?
随机推荐
Vs tool word highlight with margin
Plate - forme de surveillance par étapes zabbix
Unity3D_ Class fishing project, control the distance between collision walls to adapt to different models
Three. JS introductory learning notes 13: animation learning
2022山东智慧养老展,适老穿戴设备展,养老展,山东老博会
Unity的三种单例模式(饿汉,懒汉,MonoBehaviour)
A wave of open source notebooks is coming
AB package details in unity (super detail, features, packaging, loading, manager)
企业级日志分析系统ELK
nodejs package. JSON version number ^ and~
How to implement backspace in shell
Application example of infinite list [uigridview]
深度之眼(七)——矩阵的初等变换(附:数模一些模型的解释)
Three. JS introductory learning notes 05: external model import -c4d into JSON file for web pages
The unity vector rotates at a point
How does geojson data merge the boundaries of regions?
Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
Unity3d click events added to 3D objects in the scene
hellogolang
prometheus api删除某个指定job的所有数据