【问题标题】:how to get the actual url in php while all pages are routing through index.php in MVC frameworks当所有页面都通过 MVC 框架中的 index.php 路由时,如何在 php 中获取实际的 url
【发布时间】:2017-11-14 10:46:44
【问题描述】:

路由时,所有php脚本request_uri只显示index.php。

我想找到实际的 uri 而不是 index.php。

那么,是否有任何 php 函数或变量有助于获取实际 url。

我知道它们是获取不同框架的 url 的不同方式,但我想知道适用于每个框架的解决方案

【问题讨论】:

  • 您使用的是公共 MVC 框架吗?如果有,是哪个?
  • 我正在使用 laravel
  • 你检查过中间件吗?

标签: php


【解决方案1】:

由于您声明您使用的是 laravel,因此以下解决方案仅适用于该特定框架。

$current = url()->current(); // Returns the current url

如果您需要传递参数,获取路由名称并基于它构建 url 可以正常工作:

$current = URL::action(Route::currentRouteName(), ['arg' => 'value']); // Returns the current url and assign arguments to it

【讨论】:

  • 您的回答没有什么帮助,但我想知道该函数的内部工作原理,是否有任何方法可以使用 php 函数而不是框架相关函数
猜你喜欢
  • 2014-11-15
  • 2011-02-05
  • 1970-01-01
  • 1970-01-01
  • 2014-05-26
  • 1970-01-01
  • 2011-06-25
  • 2012-03-30
  • 2017-12-12
相关资源
最近更新 更多