使用“router.php”中的组件路由;在 Joomla 的自定义插件中
问题:如何在插件中启用来自组件 router.php 的路由?
我正在开发一个自定义插件,它将路由从默认用户配置文件重定向
index.php?option=com_users&view=profile (SEF: /component/users/profile)
到 :我自己的组件,我有额外的设置
index.php?option=com_mycomponent&view=profile (SEF: /alias/profile)
我的前端插件:
class plgSystemMyPlugin extends JPlugin
{
// constructor
function plgSystemMyPlugin( &$subject, $params ) {
parent::__construct( $subject, $params );
}
// run after the framework has loaded and the application initialize method has been called
function onAfterInitialise() {
// when component users and view profile are called
if( isset($_GET['option'], $_GET['view'])
&& $_GET['option'] == 'com_users'
&& $_GET['view'] == 'profile' )
{
$route = JRoute::_('index.php?option=com_mycomponent&view=profile' );
JFactory::getApplication()->redirect($route, null, null, true);
}
}
}
在我的组件中,所有链接都正确路由,即:
index.php?option=com_mycomponent&view=profile => /别名/个人资料
将其翻译如下:
index.php?option=com_mycomponent&view=profile => /组件/我的组件/配置文件
无法使用:
- core hacks
- .htaccess
- Joomla Redirect Plugin
Question: How do I enable the Routes from my component's router.php in a plugin?
I'm working on a custom Plugin which redirects the route from default user profile:
index.php?option=com_users&view=profile (SEF: /component/users/profile)
to my own component where I've got additional settings
index.php?option=com_mycomponent&view=profile (SEF: /alias/profile)
my front-end plugin:
class plgSystemMyPlugin extends JPlugin
{
// constructor
function plgSystemMyPlugin( &$subject, $params ) {
parent::__construct( $subject, $params );
}
// run after the framework has loaded and the application initialize method has been called
function onAfterInitialise() {
// when component users and view profile are called
if( isset($_GET['option'], $_GET['view'])
&& $_GET['option'] == 'com_users'
&& $_GET['view'] == 'profile' )
{
$route = JRoute::_('index.php?option=com_mycomponent&view=profile' );
JFactory::getApplication()->redirect($route, null, null, true);
}
}
}
In my component all links are routed correctly ie:
index.php?option=com_mycomponent&view=profile => /alias/profile
in the plugin JRoute translates it as follows:
index.php?option=com_mycomponent&view=profile => /component/mycomponent/profile
can not use:
- core hacks
- .htaccess
- Joomla Redirect Plugin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在插件 xml 文件中,您应该添加新参数,该参数将允许您选择所需的 Itemid(menuitem)
所以它应该看起来像这样
然后您需要从管理员区域的插件参数中选择具有您想要的别名的所需菜单项
然后在插件本身中就像这样使用:
这也是有效的
in the plugin xml file you should add new parameter that will allow you to choose the desired Itemid(menuitem)
so it should look like this
Then you will need to choose desired menuitem that has the alias that you wanted from the plugin parameters in the administrator area
then in the plugin itself just use like this:
and this is valid too