开发者

addScript() not work on Joomla System Plugin

开发者 https://www.devze.com 2023-03-30 06:41 出处:网络
I\'m developing a Joomla system plugin and I need to add some scripts in the header, I\'ve the following code:

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?


I've found the errors:

class PluginSystemMyPlugin extends JPlugin {
    function PluginSystemMyPlugin(&$subject, $config){

must to be:

class plgSystemMyPlugin extends JPlugin {
    function plgSystemMyPlugin(&$subject, $config){


Have 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

0

精彩评论

暂无评论...
验证码 换一张
取 消