Php 在根URL端点公开Joomla组件视图
我是joomla的新手,我正在尝试编写一个可安装的joomla组件,该组件在以下URL公开一个HTML页面:Php 在根URL端点公开Joomla组件视图,php,html,joomla,components,Php,Html,Joomla,Components,我是joomla的新手,我正在尝试编写一个可安装的joomla组件,该组件在以下URL公开一个HTML页面:http://localhost/joomla/someurl(Joomla安装在/Joomla/) 以下是我已经做过的: 我在安装中的/joomla/components/文件夹中创建了一个基本组件 我添加了一个控制器,router.php,并创建了一个要显示的视图。我的组件的名称是mycomponent 我尝试通过多种方式访问我的默认查看页面。以下工作: /joomla/compon
http://localhost/joomla/someurl
(Joomla安装在/Joomla/)
以下是我已经做过的:
/joomla/components/
文件夹中创建了一个基本组件router.php
,并创建了一个要显示的视图。我的组件的名称是mycomponent
默认
查看页面。以下工作:
/joomla/components/mycomponent
/joomla/index.php?option=com\u mycomponent
/joomla/arbirryURL/
1/您不能使用菜单链接吗?如果您的视图链接到菜单项,Joomla将自动生成url。 如果您希望允许用户在菜单中链接您的视图,这里将介绍所有内容 如果您无法将此视图链接到菜单项,我会在某些特定情况下使用系统插件。 系统插件将增强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;
}
}
/--无法直接访问
定义的('u-JEXEC')| |模具('='));
类plgSystemYourplugin扩展了JPlugin
{
初始化()后的公共函数
{
$app=JFactory::getApplication();
//去拿路由器
如果($app->isSite()){
$router=$app->getRouter();
$router->attachParseRule(数组($this,'replaceRoute'));
}
}
/**
*@param JRouterSite&$router Joomla站点路由器
*@param JURI&$uri要分析的uri
*
*@return array$vars已处理URI变量的数组
*/
公共函数replaceRoute(&$router,&$uri)
{
$array=array();
$yourURI='whateverIwant'//这是您的自定义uri
$UriSegs=sizeof(explode('/',$yourURI));
$Segs=explode(“/”,$yourURI);
$path=explode('/',$uri->getPath());
if(计数($Segs)reset();
}
返回$array;
}
}
如果用户需要该页面,这会将用户重定向到index.php?option=com_yourcomponent&view=yourView
更多信息请点击此处:
2/您只需添加到url&tmp=组件,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')代码>
这里有更多信息和你的意思是说你想创建一个sef友好的url?