How to convert links in ajax page with JoomSEF?

October 21, 2010 09:38
Tags: , , ,

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

    function display($tpl = null) {


        if ('ajaxpage' == JRequest::getVar('layout')) {
            global $mainframe;

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:

    // 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,

    $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.


One Response to “How to convert links in ajax page with JoomSEF?”

  1. Thanks for the coding you provided,it's guided me what are the changes we need to consider for this's a helpful info.