addScript() 不适用于 Joomla 系统插件
我正在开发一个 Joomla 系统插件,我需要在标头中添加一些脚本,我有以下代码:
defined('_JEXEC') or die('Restricted access');
jimport('joomla.plugin.plugin');
class PluginSystemMyPlugin extends JPlugin {
function PluginSystemMyPlugin(&$subject, $config){
parent::__construct($subject, $config);
$this->_plugin = JPluginHelper::getPlugin('system','myplugin');
$this->_params = new JParameter($this->_plugin->params);
$this->_mainframe= &JFactory::getApplication();
if($this->_mainframe->isAdmin())return;
}
function onAfterInitialise(){
if($this->_mainframe->isAdmin())return;
$loadjquery = $this->params->get('loadjquery');
$document =& JFactory::getDocument();
if($loadjquery=='yes'){
JHTML::_(' behavior.mootools');
$document->addScript("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js");
}
$document->addScriptDeclaration('
jQuery.noConflict();');
}
}
我还尝试过 addScriptDeclaration()、addStyleSheet()、addStyleSheetDeclaration(),但都不起作用。我的 Joomla 版本是 1.5.23。 我已经尝试过在 onAfterInitialise() 中使用相同声明的其他插件并且它们有效,为什么我的不行?
I'm developing a Joomla system plugin and I need to add some scripts in the header, I've the following code:
defined('_JEXEC') or die('Restricted access');
jimport('joomla.plugin.plugin');
class PluginSystemMyPlugin extends JPlugin {
function PluginSystemMyPlugin(&$subject, $config){
parent::__construct($subject, $config);
$this->_plugin = JPluginHelper::getPlugin('system','myplugin');
$this->_params = new JParameter($this->_plugin->params);
$this->_mainframe= &JFactory::getApplication();
if($this->_mainframe->isAdmin())return;
}
function onAfterInitialise(){
if($this->_mainframe->isAdmin())return;
$loadjquery = $this->params->get('loadjquery');
$document =& JFactory::getDocument();
if($loadjquery=='yes'){
JHTML::_(' behavior.mootools');
$document->addScript("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js");
}
$document->addScriptDeclaration('
jQuery.noConflict();');
}
}
I've also tried addScriptDeclaration(), addStyleSheet(), addStyleSheetDeclaration(), none working. My Joomla version is 1.5.23.
I've tried others plugin with the same declarations in onAfterInitialise() and they worked, why not mine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现错误:
必须是:
I've found the errors:
must to be:
你安装正确了吗?你发表了吗?您确定您的插件已运行吗?您是否尝试过使用
die
函数调试您的插件代码以检测其是否有效?您也可以尝试这个 http://docs.joomla.org/JDocumentHTML/addCustomTagHave you installed it correct? Have you published it? Are you sure that your plugin is run? Have you tried to debug your plugin code with
die
function to detect whether it works? Also you could try this http://docs.joomla.org/JDocumentHTML/addCustomTag