【问题标题】:How to get full url of a article by it's ID in joomla?如何通过joomla中的ID获取文章的完整网址?
【发布时间】:2014-05-16 19:13:55
【问题描述】:

我有文章ID,我如何才能获得这篇文章的有效完整网址?这篇文章已经和menu相关联了,但我可能不知道,php有没有简单的方法来获取url?我正在使用 joomla 3.2 我已经尝试过。

$article = ControllerLegacy::getInstance('Content')->getModel('Article')->getItem($article‌​Id); 
JRoute::_(ContentHelperRoute::getArticleRoute($articleId,$article->catid))

【问题讨论】:

  • ` $article = JControllerLegacy::getInstance('Content')->getModel('Article')->getItem($articleId); JRoute::_(ContentHelperRoute::getArticleRoute($articleId,$article->catid))` 它不起作用。

标签: joomla2.5 joomla3.0


【解决方案1】:

你可以这样使用

 $article = JControllerLegacy::getInstance('Content')
            ->getModel('Article')->getItem($articleId);

  $url =  JRoute::_(ContentHelperRoute::getArticleRoute($articleId, 
                      $article->catid, 
                      $article->language))

【讨论】:

    【解决方案2】:

    我写这篇文章是因为我认为这些信息对所有其他想要在 Joomla 中的任何地方获得完整当前 URL 的用户都很有用,而不仅仅是在文章中。

    在 Joomla 中使用 JURIclass 来获取 URL。 root()current()base()等函数会根据需要使用。

    echo 'Joomla root URI is ' . JURI::root();
    output:-Joomla root URI is http://localhost/joomla/
    
    echo 'Joomla current URI is ' . JURI::current();
    output:-Joomla current URI is http://localhost/joomla3/index.php/somealias
    

    注意:-current() 将给出除查询字符串部分之外的整个 URI,例如,

    如果您的完整网址是http://localhost/joomla3/index.php/somealias?id=1,那么current() 将只返回这个-> http://localhost/joomla3/index.php/somealias

    虽然,如果你使用JURI::getInstance()->toString(),那么它会返回这个->

    http://localhost/joomla3/index.php/somealias?id=1

    有关更多信息,请参阅这些链接->

    1. https://docs.joomla.org/JURI/root
    2. https://docs.joomla.org/JURI/current
    3. https://docs.joomla.org/JURI/getInstance

    【讨论】:

      【解决方案3】:

      也许JURI(来自 Joomla! API)可以帮助您:

      示例:

      echo 'Joomla current URI is ' . JURI::current() . "\n";
      

      可能输出

      Joomla base URI is http://localhost/joomla/
      

      【讨论】:

      • 你真的读过这个问题吗?我需要文章的 url 的 id。不是 joomla 网址
      • 我认为侮辱试图帮助你的人不会让你的格式错误的问题得到回答。
      • 我没有侮辱任何人,只是建议人们如果他们真的没有阅读问题,请不要回答,我的意思是问题的标题。我也对你对问题的负面评价感到惊讶。人们只是在网上找不到正确答案后才来这里提问
      • @user2737980 我根据我的理解回答了。我发布的解决方案是实现您想要的方法之一。
      猜你喜欢
      • 1970-01-01
      • 2014-04-13
      • 2015-05-04
      • 1970-01-01
      • 2011-08-28
      • 1970-01-01
      • 1970-01-01
      • 2013-08-15
      • 1970-01-01
      相关资源
      最近更新 更多