1
votes

I am writing a Joomla module that accesses the K2 tables such as K2 Items and K2 Category. I have managed to pull out the K2 Items I wish from the MySQL database for display, but I want to be able to create a clickable link to the K2 Item or its K2 Category. I am not able to find this information. I have looked at the K2 Item template, but if I attempt to use the same code for the link it doesn't include the full path. It leaves out http:// and the domain.

Is creating a link to a K2 Item or K2 Category in Joomla different than how the link must be created for a Joomla Article or Joomla Category? Either way, how do I create one for K2 Items and K2 Categories in my Joomla module.

Here is a PHP code example I am using from the Joomla K2:

$db = & JFactory::getDBO();
$category = & JTable::getInstance('K2Category', 'Table');
$category->load($catid);
$item->category=$category;
$item->category->link = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($category->id.':'.urlencode($category->alias))));

echo $item->category->link;

This prints out the path, but it doesn't include the domain. /joomla/index.php/component/k2/itemlist/category/4-something-here What I'm expecting it to print out in this example to make it a valid link to the category: http://example.com/joomla/index.php/component/k2/itemlist/category/4-something-here

1

1 Answers

1
votes

If you want to get the base URL for the site, you can use JURI::base() to get it. I'm not entirely sure what you want to do, but it may be a better idea for you to grab the application with JFactory::getApplication(); and then use setRedirect.