如何在启用 SEF 的情况下查找非 SEF URL(Joomla 1.5)?

发布于 2024-07-24 04:47:06 字数 314 浏览 3 评论 0原文

我知道您可能不会遇到很多这样的问题...

我正在开发一个组件,我希望能够在启用 SEF 时处理非 SEF URL,无论是内置 SEF 还是其他东西像sh404sef。

Joomla 是否将原始非 SEF URL 存储在任何地方 即。 index.php?com=com_fred&view=主页?

我发现任何激活的 SEF 都会将 JURI::getInstance() 值更改为 SEF 等效值。 我还发现 $REQUEST['U​​RI'] 值不适用于所有平台/服务器等。

感谢您的帮助

I know you probably don't get many questions like this...

I am working on a component that I want to be able to deal with the non-SEF URLs whilst SEF is enabled, whether it be the built-in SEF or something like sh404sef.

Does Joomla store the ORIGINAL non-SEF URL anywhere ie. index.php?com=com_fred&view=homepage?

I've found that any SEF activated, changes the JURI::getInstance() value to the SEF equivilant.
I've also found the the $REQUEST['URI'] value does not work on all platforms/servers etc.

Thanks for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

喜爱皱眉﹌ 2024-07-31 04:47:06
  1. GET/POST 请求中的所有变量获取到一个数组中。 此时,您还可以在生成 URL 字符串之前修改这些值。

    $getVars = JRequest::get( 'GET' ); 
      
  2. 如果您确实需要 URL 字符串,可以通过以下方式获取:

    $newURL = http_build_query($getVars); 
      

希望有帮助!

  1. Get all vars from the GET/POST request into an array. At this point you may also modify the values before generating the URL string.

    $getVars = JRequest::get( 'GET' );
    
  2. If you really need the URL string, you can obtained with:

    $newURL = http_build_query($getVars);
    

Hope it helps!

木槿暧夏七纪年 2024-07-31 04:47:06

我回到这段代码并再次尝试,但给了我一些错误,所以我根据我之前用这个新答案制定的先前答案部分地重新设计了它(在 Joomla!3.4.5 上工作得很好)

// build the JInput object 
$jinput = JFactory::getApplication()->input;
// retrieve the array of values from the request (stored in the application environment) to form the query 
$uriQuery = $jinput->getArray();
// build the the query as a string
echo 'index.php?' . JUri::buildQuery($uriQuery);

Joomla! API 文档:JInput - JUri

上一个答案:< /强>
谷歌搜索我发现了这个

<?php
  // "unparse" the Joomla SEF url to get the internal joomla URL
  JURI::current();// It's very strange, but without this line at least Joomla 3 fails to fulfill the task
  $router =& JSite::getRouter();// get router
  $query = $router->parse(JURI::getInstance()); // Get the real joomla query as an array - parse current joomla link
  $url = 'index.php?'.JURI::getInstance()->buildQuery($query);
?>

我'已经用 Joomla 测试过了! 3.4.4 及其工作正常! 不知道1.5能不能用

I came back to this code and tried again but gave me some errors, so I've reworked it partially based on the previous answer I've formulated before with this new one (working nice on Joomla! 3.4.5)

// build the JInput object 
$jinput = JFactory::getApplication()->input;
// retrieve the array of values from the request (stored in the application environment) to form the query 
$uriQuery = $jinput->getArray();
// build the the query as a string
echo 'index.php?' . JUri::buildQuery($uriQuery);

Joomla! API Docs: JInput - JUri

PREVIOUS ANSWER:
Googling around I found this:

<?php
  // "unparse" the Joomla SEF url to get the internal joomla URL
  JURI::current();// It's very strange, but without this line at least Joomla 3 fails to fulfill the task
  $router =& JSite::getRouter();// get router
  $query = $router->parse(JURI::getInstance()); // Get the real joomla query as an array - parse current joomla link
  $url = 'index.php?'.JURI::getInstance()->buildQuery($query);
?>

I've tested it with Joomla! 3.4.4 and its working fine! Dunno if it can work with 1.5

心碎无痕… 2024-07-31 04:47:06

您可以使用 JRequest::get(true) 从 URL 获取所有查询参数的数组。 不过,请注意,我还没有对其进行足够的检查,无法知道它是否只返回 GET 参数,还是返回所有 REQUEST 参数(我认为更有可能)。 但是,它可能对您正在寻找的内容有所帮助。

You can use JRequest::get(true) to get an array of all the query parameters from the URL. A quick note though, I haven't checked it enough to know if it only returns GET parameters or it does all REQUEST parameters (which I think is more likely). It might, however, help with what you're looking for.

月棠 2024-07-31 04:47:06

对于菜单项,它存储在“jos_menu”表的“link”列中(但 itemid 不在该字符串中 - 它是“id”列)。

对于其他任何事情,它可能不会存储在数据库中,但通常可以很容易地计算出来,尤其是对于核心组件。 使用第三方组件可能会有点麻烦,但您可以查看大多数组件的 MVC 架构来解决这个问题。

否则,您始终可以在开发站点上关闭 SEF/为此创建一个开发站点。

您对某个特定组件感到好奇吗?

For menu items, it's stored in the 'jos_menu' table, in the 'link' column (but the itemid is not in this string - it's the 'id' column).

For anything else, it's probably not stored in the database, but can normally be worked out pretty easily, especially with core components. It can be a little bit of a pain with third party components, but you can look through the MVC architecture of most components to figure it out.

Otherwise, you could always turn off SEF on your dev site/create a dev site for this.

Is there a specific component that you're curious about?

酸甜透明夹心 2024-07-31 04:47:06

我在这里发布的链接:
Joomla URL:一篇文章没有本身没有漂亮的 URL?

为 Joomla 1.5 中的 URL 提供了一个非常好的“速成课程”

The link that I posted here:
Joomla URLs: An article doesn't have a pretty URL by itself?

provides a very good "crash course" for URLs in Joomla 1.5

凉栀 2024-07-31 04:47:06

您无需对非 SEF URL 执行任何特殊操作。 即使您打开了 SEF URL,如果有人使用非 SEF URL 访问站点,Joomla 仍将显示正确的页面。 组件中处理 SEF URL 的部分(路由器)仅告诉 Joomla 如何使用 URL 信息来确定要显示的内容。 当出现非 SEF URL 时,Joomla 只会像平常一样解析查询字符串。

对于任何给定的组件,URL都是这样构建的 -

index.php?option=com_name&view=XXXX&id=1111&Itemid=11111

  • option 是组件的名称
  • view 当然是要显示的视图
  • id 是 id特定内容项的
  • itemid 是用于确定模块/模板分配的菜单项

You don't have to do anything special for non-SEF URLs. Even if you have SEF URLs turned on, Joomla will still display the correct page if someone access the site with a non-SEF URL. The portion of your component that handles SEF URLs, the router, only tells Joomla how to use the URL information to determine what to display. When presented with a non-SEF URL Joomla just parses the query string as it normally would.

For any given component, the URL is built like this -

index.php?option=com_name&view=XXXX&id=1111&Itemid=11111

  • option is the name of the component
  • view is of course which view to display
  • id is the id of the particular content item
  • itemid is the menu item it used to determine module/template assignment
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文