[英]Exposing Joomla component view at root URL endpoint
我是joomla的新手,我試圖編寫一個可安裝的Joomla組件,該組件在以下URL處公開HTML頁面: http://localhost/joomla/someurl
(Joomla安裝在/ joomla /)
這是我已經完成的工作:
/joomla/components/
文件夾中創建了一個基本組件 router.php
並創建了一個要顯示的視圖。 我組件的名稱是mycomponent
default
視圖頁面。 以下工作:
/joomla/components/mycomponent
/joomla/index.php?option=com_mycomponent
我有以下問題:
/joomla/arbitraryurl/
1 /您不能使用菜單鏈接,如果視圖鏈接到菜單項,則Joomla會自動生成網址。 如果要允許用戶在菜單中鏈接視圖,請在此處進行全部說明: http://docs.joomla.org/J3.x:Developing_a_MVC_Component / Adding_a_menu_type_to_the_site_part
如果您不能將此視圖鏈接到菜單項,則在某些特定情況下,我將使用系統插件。 系統插件將增強JRouter,您將能夠將任何URL路由到組件。
//-- No direct access
defined('_JEXEC') || die('=;)');
class plgSystemYourplugin extends JPlugin
{
public function onAfterInitialise()
{
$app = JFactory::getApplication();
// get the router
if ($app->isSite()) {
$router = $app->getRouter();
$router->attachParseRule(array($this, 'replaceRoute'));
}
}
/**
* @param JRouterSite &$router The Joomla Site Router
* @param JURI &$uri The URI to parse
*
* @return array $vars The array of processed URI variables
*/
public function replaceRoute (&$router, &$uri)
{
$array = array();
$yourURI = 'whateverIwant' //here is your custom uri
$UriSegs = sizeof(explode('/',$yourURI));
$Segs = explode('/',$yourURI);
$path = explode('/',$uri->getPath());
if(count($Segs) < count($path)){
for ($index = $UriSegs-1; $index < count($Segs); $index++) {
if($Segs[$index]!==$path[$index]){
return $array;
}
}
if(!isset($path[1]) || $path[1]===''){
return $array;
}
JRequest::setVar('option','com_yourcomponent');
JRequest::setVar('view','yourView');
$uri->reset();
}
return $array;
}
}
如果用戶需要頁面http://yourdomaine.com/whateverIwant,這會將用戶重定向到index.php?option = com_yourcomponent&view = yourView。
此處提供更多信息: http : //docs.joomla.org/J2.5 : Creating_a_System_Plugin_to_augment_JRouter
2 /您只需將其添加到url&tmp = component中,Joomla將刪除標准模板和模塊,並將僅呈現該組件。
3 /您可以使用
對於腳本:
$document->addScript(JURI::root().'components/com_yourcomponent/assets/js/script.js');
對於CSS文件:
$document->addStyleSheet(JURI::root().'components/com_yourcomponent/assets/css/style.css');
有關更多信息,請參見http://docs.joomla.org/Adding_JavaScript和http://docs.joomla.org/JDocument/addStyleSheet
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.