Symfony2实现在controller中获取url的方法
作者:Surfin 时间:2023-11-17 17:30:03
本文实例讲述了Symfony2实现在controller中获取url的方法。分享给大家供大家参考,具体如下:
// 假设当前URL地址是http://192.168.1.100/demo/web/app_dev.php/m/index
$request = $this->getRequest();
// http or https 此处为http
$request->getScheme();
// 192.168.1.100
$request->getHttpHost();
// http://192.168.1.100
$request->getSchemeAndHttpHost();
// /demo/web/
$request->getBasePath();
// /demo/index.php
$request->getBaseUrl();
// eg: /demo/web/app_dev.php/user/login 不一定是/demo/web/app_dev.php/m/index 取决于routeName
$this->generateUrl('routeName');
// routeName
$routeName = $request->get('_route');
希望本文所述对大家基于Symfony框架的PHP程序设计有所帮助。
标签:Symfony2,controller,url
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python numpy大矩阵运算内存不足如何解决
2022-08-06 22:38:21
![](https://img.aspxhome.com/file/2023/9/92509_0s.png)
python pands实现execl转csv 并修改csv指定列的方法
2022-11-20 01:45:27
三种SQL分页查询的存储过程代码
2012-01-05 19:31:32
PHP版微信小店接口开发实例
2023-11-10 11:56:06
详解JS中的compose函数和pipe函数用法
2024-04-18 10:59:25
对Python中 \\r, \\n, \\r\\n的彻底理解
2022-09-14 07:00:15
![](https://img.aspxhome.com/file/2023/7/72117_0s.jpg)
go并发实现素数筛的代码
2024-04-27 15:38:03
![](https://img.aspxhome.com/file/2023/9/133969_0s.png)
python编程使用协程并发的优缺点
2023-07-20 12:11:45
python用opencv将标注提取画框到对应的图像中
2023-01-18 21:10:16
![](https://img.aspxhome.com/file/2023/5/72845_0s.png)
MySql的事务使用与示例详解
2024-01-27 17:24:50
Python3如何将源目录中的图片用MD5命名并可以设定目标目录
2023-11-28 10:33:17
9个个人网站制作诀窍
2007-12-13 11:36:00
CSS控制Table表格文字样式
2008-06-11 18:53:00
![](https://img.aspxhome.com/file/UploadPic/20086/11/2008611185824325s.jpg)
Golang CSP并发机制及使用模型
2023-09-15 16:13:27
![](https://img.aspxhome.com/file/2023/4/101674_0s.jpg)
python实现监控指定进程的cpu和内存使用率
2023-08-23 02:21:17
![](https://img.aspxhome.com/file/2023/3/62003_0s.jpg)
Web 标准要求一览表
2009-01-08 12:35:00
Python获取当前时间的方法
2022-06-11 18:24:03
Golang中Interface接口的三个特性
2024-04-23 09:35:46
MySQL8.0.23版本的root密码重置最优解法
2024-01-17 19:52:12
![](https://img.aspxhome.com/file/2023/4/101514_0s.png)
pytorch 把图片数据转化成tensor的操作
2022-01-14 19:02:46
![](https://img.aspxhome.com/file/2023/6/118106_0s.jpg)