Keyword

Get K2 (Joomla) item url with SEF

  • Stanislav Flusov
  • Stanislav Flusov's Avatar Topic Author
  • Offline
  • New Member
More
11 years 3 months ago - 11 years 3 months ago #115210 by Stanislav Flusov
Get K2 (Joomla) item url with SEF was created by Stanislav Flusov
Goog day!

I'm write custom RSS-channel that will use a mobile application for reading news from my site. As the data source I'm used K2 installed on Joomla 2.5.6.

At this moment I'm write a class that returns a link to an article without SEF, for example:
- index.php?option=com_k2&view=item&id=4774:poshlinu-na-kombayny-ppiostanovili&Itemid=354

But would like to have such a link:
- /economics/customs-union/4774-poshlinu-na-kombayny-ppiostanovili.html

Thanks for your help.
class RssModel extends JApplicationWeb
    {  
        public function __construct(JInput $input = null, JRegistry $config = null, JWebClient $client = null) 
        {
            parent::__construct($input, $config, $client);

            $this->execQuery();
        }

        public $ObjectList;

        protected function execQuery()
        {
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);

            $query->select('items.id, items.alias, items.created, items.introtext, items.fulltext, items.title') 
                  ->select('cat.id as catid, cat.alias as catalias, cat.name as catname', ', ')
                  ->select('usr.name as username, usr.email as useremail', ', ');

            $query->from('#__k2_items as items')
                  ->leftJoin('#__k2_categories as cat on items.catid = cat.id')
                  ->leftJoin('#__users as usr on items.created_by = usr.id');

            $query->where('items.created_by != 55 AND items.created_by != 42')
                  ->where('items.published = 1 AND items.trash = 0', 'AND')
                  ->where('cat.published = 1 AND cat.trash = 0', 'AND')
                  ->where('(TO_DAYS(NOW()) - TO_DAYS(items.created)) <= 2', 'AND');

            $query->order('items.created desc');

            $db->setQuery($query);

            $this->ObjectList = $db->loadObjectList();        
        }

        protected $domain;

        public function getLink($item, $domain = 'http://localhost/')
        {
          $this->domain = $domain;   

          $article = (iconv_strlen($item->alias)) ? $item->id.':'.$item->alias : $item->id;
          $category = (iconv_strlen($item->catalias)) ? $item->catid.':'.$item->catalias : $item->catid;

          return htmlspecialchars(
                  $domain.K2HelperRoute::getItemRoute($article, $category), ENT_QUOTES, 'UTF-8');
        }
}

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 3 months ago #115211 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Get K2 (Joomla) item url with SEF
Hello Stanislav,

First of all you need to update Joomla! to 2.5.11 asap.

Furthermore are you using Joomla!'s SEF settings?

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum