Joomla 乔姆拉从按钮';s iframe处理程序

Joomla 乔姆拉从按钮';s iframe处理程序,joomla,joomla2.5,joomla-extensions,joomla3.2,Joomla,Joomla2.5,Joomla Extensions,Joomla3.2,我在做一个Joomla!2.5/3.x编辑器xtd按钮,我在单击按钮时从文件加载布局时遇到问题 我尝试过这种方法: $link = 'plugins/editors-xtd/myplugin/myplugin.layout.php?name='.$name; $button = new JObject; $button->modal = true; $button->class = 'btn'; $button->link = $link; $button->text

我在做一个Joomla!2.5/3.x编辑器xtd按钮,我在单击按钮时从文件加载布局时遇到问题

我尝试过这种方法:

$link = 'plugins/editors-xtd/myplugin/myplugin.layout.php?name='.$name;

$button = new JObject;
$button->modal = true;
$button->class = 'btn';
$button->link  = $link;
$button->text  = 'Insert something';
$button->name  = 'myplugin';
$button->options = "{handler: 'iframe', size: {x: 500, y: 300}}";
。。。但是在admin中生成的完整链接看起来像。。但它不起作用。我还尝试在$link中包含JURI::base,但管理员路径仍然被加载

我是Joomla插件开发的新手!我已经搜索了很多,但没有找到解决方案

**我还尝试了一个像index.php?folder=plugins.editors xtd.myplugin&file=myplugin.layout.php&name=$name这样的链接,但仍然没有。 是否有此方面的训练计划,或者我必须创建并使用javascript函数在单击按钮时运行?

解决方案 像这样修改链接变量(如果应用程序是admin):

。。。和删除按钮选项(这意味着文件内容将通过ajax内部模式加载)

此外,在myplugin.layout.php中,我们可以添加一些安全检查,并导入Joomla!框架库和定义,以便我们可以利用Joomla!我们文件中的框架(例如语言加载) 这是我的实际文件头:

<?php

// No direct access
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); 
if( ! IS_AJAX) die;

// Include J!Framework for later use
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../..'));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE.DS.'includes'.DS.'defines.php');
require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php');

//more magic goes here...

不幸的是,JED检查程序要求所有php文件都以
定义的(“'u JEXEC')或die开头在代码的第一行,因此如果您想在extensions.joomla.org上共享它,那么您将被阻止…

返回OP,您可以在生成链接之前检测您是否在管理员或站点中:

$app=JFactory::getApplication();
// ...
如果($app->isAdmin()){
$root='../';//Joomla需要相对路径,请将站点文件夹保留为“管理员”
}否则{
$root='';
}
$button->link=$root./plugins/editors xtd/myplugin/myplugin.layout.php?name='.$name;
另外,您可能已经知道
$button->name='myplugin'
需要是Joomla icomoon集合中图标的名称-您可以在此处看到它们 名称必须是图标名称,不带
.icon-
位,例如:
$button->name='warning-2'


代码块似乎工作不正常…很抱歉格式化

我看不到定义
IS\u AJAX有任何好处。只需在一个
if
表达式中写入这些检查,而无需创建常量,并在需要时终止。
<?php

// No direct access
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); 
if( ! IS_AJAX) die;

// Include J!Framework for later use
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../..'));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE.DS.'includes'.DS.'defines.php');
require_once ( JPATH_BASE.DS.'includes'.DS.'framework.php');

//more magic goes here...