コンポーネントのベース ファイル ( にありますcomponents/com_yourname/yourname.php
) で、設定されているコンポーネントを確認し、設定されていない場合は設定します (または設定する URL にリダイレクトします)。
$app = JFactory::getApplication();
$menu = $app->getMenu();
$jinput = $app->input;
// check if they are on the default menu item (i.e. not your component's)
// also check if the template is set already
if ($menu->getActive() == $menu->getDefault() && $jinput->get('template') != 'comtemplate') {
// you might be able to get away with this, I haven't tested this
$jinput->set('template', 'comtemplate');
// otherwise set up a redirect
// get the current url of the page
$url = $_SERVER['REQUEST_URI'];
// check if '?' already exists in the url
// if it does then there is already the start of the query string so we should
// use '&' to tack on the new query item
// if not then start the query string with '?'
$url .= (strpos($url, '?')===FALSE ? '?' : '&') . 'template=comtemplate';
// take the new url and redirect to it.
//This should update the url in the browser for the user
$app->redirect($url);
// since you redirected, no sense letting anything else run here, so exit
exit();
}
更新:コードにより良いコメントを追加したので、私がやろうとしていることを理解していただければ幸いです。