How to convert links in ajax page with JoomSEF?
Recently one of my company websites decided to use JoomSEF for SEO (Joomla 1.5.20 and JoomSEF 3.7.4). Because some custom components are developed in this website, so some extension of JoomSEF for these custom components are needed. Everything goes smooth … except the ajax page …
The following codes are placed in view.html.php
<?php function display($tpl = null) { ... ... parent::display($tpl); if ('ajaxpage' == JRequest::getVar('layout')) { global $mainframe; $mainframe->close(); } } ?>
Because the application is closed, no plugin or other action can be taken. All the links in this ajax page haven’t converted by JoomSEF.
I don’t know how to call plugin by system function individually, so my solution is to call JoomSEF directly.
In my ajax page (ajaxpage.php inside tmpl), first create JoomSEF router object:
<?php // create JRouterJoomsef object if JoomSEF is installed if (class_exists('JRouterJoomsef')) { $jRouterJoomsef = new JRouterJoomsef(); } else { // no JoomSef installed $jRouterJoomsef = null; } ?>
Then before you paste the link to HTML A tag,
<?php $link = 'index.php?option=com_customcomponent&view=xxxx&id='.$object->id.'&Itemid=101'; if (null != $jRouterJoomsef) { // JoomSEF installed and published $link = $jRouterJoomsef->build($link)->getPath(); } ?>
If you installed and published the JoomSEF, the JRouterJoomsef object should be created. Then you can use its function build() to return JURI object, then use JURI’s getPath() function to paste the sef’ed path.
Hope this help, thanks.
Updated on 22 October 2010:
JoomSEF Support Team replied that it can be done simply by JRoute::_() function:
$link = JRoute::_('index.php?option=com_customcomponent&view=xxxx&id='.$object->id.'&Itemid=101');
No matter you turn on or off either the SEF or JoomSEF, JRoute will take care for you. So just one sentence and it’s done.
Thanks JoomSEF Support Team.
Thanks for the coding you provided,it's guided me what are the changes we need to consider for this issue.it's a helpful info.