Url Sef in ajax module joomla

536 Views Asked by At

Hi everyone and thanks in advance for the help you can give me.

I am creating a joomla module to show articles via ajax, I'm almost finished, I have the problem with the url.

The problem is that the module makes a call via ajax to search.php. All returns me well except the url.

The url that returns me is: /www.miste.com/modules/mod_mymodule/index.php?option=com_content&view=article&id=12:mi-title-article&catid=10&Itemid=107

The right thing would be: / www.miste.com/index.php?option=com_content&view=article&id=12:mi-title-article&catid=10&Itemid=107

Part of my code is as follows:

if ( !$_GET ) exit;
if ( !defined( "_JEXEC" ) ) define( "_JEXEC", "\r\n" ) or die('Restricted access');

define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', dirname(dirname(dirname(__FILE__))) );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
require_once ( JPATH_BASE.DS.'components'.DS.'com_content'.DS.'router.php');
require_once (dirname(__FILE__).'/helper.php');

/** CREATE THE APPLICATION**/
$mainframe = JFactory::getApplication('site');
/**INITIALISE THE APPLICATION**/
$mainframe->initialise();

if(modFpncrFilterArticlesHelper::validaSelect($selectDestino) && modFpncrFilterArticlesHelper::validaOpcion($opcionSeleccionada))
    {
    $tabla=$listadoSelects[$selectDestino];

        $db = JFactory::getDbo();
        $query = $db->getQuery(true)
            ->select('id, title, alias, catid')
            ->from('#__content')
            ->where('catid="'.$opcionSeleccionada.'"')
            ->where('state=1');
        $db->setQuery($query);
        $allarticles = $db->loadObjectList('id');

    // Comienzo a imprimir el select
    $InputsArticles = '';
        foreach ($allarticles as $article){

$catslug = $article->catid;
$slug = $article->id.':'.$article->alias;
$link = JRoute::_(ContentHelperRoute::getArticleRoute($slug, $catslug));            

$UrlArticle = JRoute::_( ContentHelperRoute::getArticleRoute($article->id.":".$article->alias, $article->catid), true); 
                $InputsArticles .= "<option value='". $link ."'>".$article->title."</option>";
            }
        $InputsArticles = $InputsArticles;
    }
    ?>
<select name="<?php echo $selectDestino; ?>" id="<?php echo $selectDestino; ?>" onChange='cargaContenido(this.id)'>
    <option value="0"><?php echo $article_label_active; ?></option>
    <?php echo $InputsArticles; ?>
</select>
<input type="button" name="go" value="<?php echo $button_label; ?>" onclick="check_send();" class="btn btn-success" id="send">

Thanks in advance for the help you can give me

2

There are 2 best solutions below

0
On

have you tried without using the contenthelperroute? It might not be suited when called from a module. Try:

$link=JRoute::_("index.php?option=com_content&view=article&id={$article->id}&catid={$article->catid}");

Also, looks like some mess there in your code where you have both the $link and the $UrlArticle - variables, but the latter is never used (in your code-fragment anyway)

1
On

I had used some thing like this when i had developed a module.

$article->slug = $article->id.':'.$article->alias; $article->catslug = $article->catid ? $article->catid .':'.$article->category_alias : $article->catid;

echo JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug));

This is inside the loop.