问题:如何在插件中启用来自组件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 => /alias /profile
在插件 JRoute 中将其翻译如下:
index.php?option=com_mycomponent&view=profile => /component/mycomponent /profile
不能用:
- 核心黑客
- .htaccess
- Joomla 重定向插件