1

質問: プラグインでコンポーネントの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リダイレクトプラグイン
4

1 に答える 1

2

プラグイン xml ファイルで、目的の Itemid(menuitem) を選択できるようにする新しいパラメーターを追加する必要があるため、次のようになります。

<param name="menuitem" name="my_itemid" title="Target Itemid" description=""/>

次に、管理者領域のプラグイン パラメータから必要なエイリアスを持つ目的のメニュー項目を選択し、プラグイン自体で次のように使用する必要があります。

$route = JRoute::_('index.php?Itemid='.$this->params->get('my_itemid') );

そしてこれも有効です

$route = JRoute::_('index.php?option=com_mycomponent&view=profile&Itemid='.$this->params->get('my_itemid') );
于 2011-06-29T09:29:28.183 に答える