drl92080 2017-12-21 15:16
浏览 70
已采纳

Joomla SEF自定义组件任务的URL

I am quite new to Joomla! and building a custom component to provide API services. Below is the url to the component function :

http://www.example.com/index.php?option=com_componentA&task=ajax.functionA&format=json

I would like to change it to become :

http://www.example.com/componentA/functionA

Is there any idea I could achieve that?

I tried rewrite on .htaccess for that particular url but Joomla! will redirect it back to index.php.

Also tried installing joomsef by ARTIO but it did not work.

Thanks in Advance!

  • 写回答

1条回答 默认 最新

  • dory4404 2017-12-21 19:19
    关注

    After a few more hours of testing I've solved it. I've added router.php to my component folder with two functions in it "[componentName]BuildRoute" and "[componentName]ParseRoute" to override original function. Refer Joomla! Documentation.

    [componentName]BuildRoute will be the function building SEF or custom URL.
    - This function will return an array where element in it will be concatenate to build the custom URL. - Depends on what you return in the array will determine the URLstructure.
    For eg. :

    http://www.example.com/index.php?option=com_componentA&task=ajax.functionA&format=json

    BuildRoute need to return array("ajax", "functionA");

    and translate into http://www.example.com/component/componentA/ajax/functionA

    [componentName]ParseRoute will be the function to convert your custom URL back to internal URL.

    • This function will input an array where each of the element will be use to determine the internal URL.

    • Then using the parameter to rebuild a return array that map back to internal link

    For Eg. :

    http://www.example.com/component/componentA/ajax/functionA

    ParseRoute parameter will be array("ajax", "functionA")

    ParseRoute needs to return array("task" => "ajax.createPolicyResult", "format"=>"json");

    http://www.example.com/index.php?option=com_componentA&task=ajax.functionA&format=json


    I cant remove the "component" from the URL else it won't work but its OK for me. As the "componentA" is needed as well so that it will call the router.php file in my custom component folder.

    Hope this help =)

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

报告相同问题?

悬赏问题

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