推进joomla自定义组件的url sef

时间:2014-03-01 15:38:19

标签: php redirect joomla components

你好我在谷歌上搜索但没有解决方案......

我在joomla3上开发了一个组件

使用joomla sef组件的addreess是这样的:

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

带菜单:domain.com/menu_name/view_name/keyword/2005/1/4

没有菜单:domain.com/component/bahaedini/view_name/keyword/2005/1/4

我最喜欢的域名为:domain.com/keyword/2005/1/4

但至少如何删除URL中的“view_name”或“component / bahaedini”?

我可以通过访问来删除它但我无法将参数发送到组件...

我希望至少有这些格式:

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

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;
}?>

1 个答案:

答案 0 :(得分:2)

设置为$segments的任何内容都会显示在网址中。因此,$segments[] = $query['view'];将视图添加到网址。由于您的解析器自动设置视图,仍然在构建函数中取消设置视图,但不要将其推入$segments

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

当然,您可能需要调整解析器,因为现在段的数量会有所不同,因此您需要不同的索引值。