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 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办