【问题标题】:How to find the non-SEF URL whilst SEF is enabled (Joomla 1.5)?如何在启用 SEF 时找到非 SEF URL(Joomla 1.5)?
【发布时间】:2010-11-02 16:13:58
【问题描述】:

我知道你可能不会有很多这样的问题......

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

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

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

感谢您的帮助

【问题讨论】:

  • 你不是说$_SERVER['REQUEST_URI']吗?

标签: joomla joomla1.5 joomla-sef-urls


【解决方案1】:

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

除此之外,它可能不存储在数据库中,但通常可以很容易地计算出来,尤其是核心组件。使用第三方组件可能会有点麻烦,但是您可以查看大多数组件的 MVC 架构来弄清楚。

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

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

【讨论】:

    【解决方案2】:

    我在这里发布的链接: Joomla URLs: An article doesn't have a pretty URL by itself?

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

    【讨论】:

      【解决方案3】:

      您不必为非 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 是组件的名称
      • 视图当然是显示哪个视图
      • id 是特定内容项的 id
      • itemid 是用于确定模块/模板分配的菜单项

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          【解决方案5】:
          1. GET/POST 请求中获取所有变量到一个数组中。此时,您还可以在生成 URL 字符串之前修改这些值。

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

            $newURL = http_build_query($getVars);
            

          希望对您有所帮助!

          【讨论】:

            【解决方案6】:

            我回到这段代码并再次尝试,但给了我一些错误,所以我根据之前用这个新的答案制定的部分重新设计了它(在 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


            以前的答案: 谷歌搜索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);
            ?>
            

            我已经用 Joomla 测试过它! 3.4.4 和它的工作正常!不知道它是否可以与 1.5 一起使用

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2012-01-31
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多