问题
I have article id, How can I get valid full url of this article? This article already associated with menu but I might not know, is there any easy way in php to get url? I am using joomla 3.2 I tried following already.
$article = ControllerLegacy::getInstance('Content')->getModel('Article')->getItem($articleId);
JRoute::_(ContentHelperRoute::getArticleRoute($articleId,$article->catid))
回答1:
You can use like this
$article = JControllerLegacy::getInstance('Content')
->getModel('Article')->getItem($articleId);
$url = JRoute::_(ContentHelperRoute::getArticleRoute($articleId,
$article->catid,
$article->language))
回答2:
I am writing this because I think this information is useful to all other users who want full current URL anywhere in Joomla not only in articles.
In Joomla use JURI
class to get URLs.
Functions like root()
, current()
& base()
will be used according to the need.
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
Note:- current()
will give the whole URI except the query string part, for example,
IF your full URL is http://localhost/joomla3/index.php/somealias?id=1 then current()
will only return this-> http://localhost/joomla3/index.php/somealias
While, if you use JURI::getInstance()->toString()
then it will return this->
http://localhost/joomla3/index.php/somealias?id=1
For more information see these links->
- https://docs.joomla.org/JURI/root
- https://docs.joomla.org/JURI/current
- https://docs.joomla.org/JURI/getInstance
回答3:
Maybe the JURI (from Joomla! API) help you:
exemple:
echo 'Joomla current URI is ' . JURI::current() . "\n";
might output
Joomla base URI is http://localhost/joomla/
- JURI class
来源:https://stackoverflow.com/questions/23702983/how-to-get-full-url-of-a-article-by-its-id-in-joomla