简体   繁体   中英

Advance url sef for joomla custom component

Hi there I googled for house but no solution...

I developed a component on joomla3

with The joomla sef the addreess of component is this:

orginal address: domain.com/index.php?option=com_bahaedini&keyword=22&year=2005&month=1&day=4

with menu: domain.com/menu_name/view_name/keyword/2005/1/4

without menu: domain.com/component/bahaedini/view_name/keyword/2005/1/4

My favariate domain is: domain.com/keyword/2005/1/4

But at least how can remove "view_name" or "component/bahaedini" in the URL?

I can remove it by hatccess but I can not sent parametrs to component...

I want to have at least on of these format:

domain.com/keyword/2005/1/4
domain.com/menu_name/keyword/2005/1/4

or

domain.com/view_name/keyword/2005/1/4
domain.com/bahaedini/keyword/2005/1/4



<?php
defined('_JEXEC') or die ;


//http://127.0.0.1/archives?option=com_bahaedini&view=items&date=2014-12-9
function BahaediniBuildRoute(&$query)
{
       $segments = array();
       if(isset($query['view']))
       {
                $segments[] = $query['view'];
                unset( $query['view'] );
       }

       if(isset($query['keyword']))
       {
                $segments[] = $query['keyword'];
                unset( $query['keyword'] );
       }

       if(isset($query['year']))
       {
                $segments[] = $query['year'];
                unset( $query['year'] );
       }
       if(isset($query['month']))
       {
                $segments[] = $query['month'];
                unset( $query['month'] );
       }
       if(isset($query['day']))
       {
                $segments[] = $query['day'];
                unset( $query['day'] );
       }


       return $segments;
}

//http://127.0.0.1/archives?option=com_bahaedini&view=items&date=2014-12-9
function BahaediniParseRoute($segments)
{
       $vars = array();


       switch($segments[0])
       {

               case 'items':
                       $vars['view'] = 'items';

                       if(isset($segments[2]))
                       {
                       $year = explode( ':', $segments[2] );
                       $vars['year'] =  (int)$year[0];
                       }

                       if(isset($segments[3]))
                       {
                       $month = explode( ':', $segments[3] );
                       $vars['month'] = (int)$month[0]; 
                       }

                       if(isset($segments[4]))
                       {
                       $day = explode( ':', $segments[4] );
                       $vars['day'] = (int)$day[0]; 
                       }

                       if(isset($segments[1]))
                       {
                       $search = explode( ':', $segments[1] );
                       $vars['keyword'] = (int)$search[0]; 
                       }

                       break; 


       }
       return $vars;
}?>

Anything set to $segments will appear in the url. So this $segments[] = $query['view']; adds the view to the url. Since your parser automatically sets the view, still unset the view in the build function, but don't push it into $segments :

function BahaediniBuildRoute(&$query)
{
   $segments = array();
   if(isset($query['view']))
   {
            unset( $query['view'] );
   }
   ...

Naturally, you may have to adjust your parser, since now the number of segments will be different, so you will need different index values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM