duannian7116 2014-03-01 15:38
浏览 45
已采纳

推进joomla自定义组件的url sef

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;
}?>
  • 写回答

1条回答 默认 最新

  • duandao1931 2014-03-02 03:34
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?