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 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: