2011-03-17 23 views
0

我正在使用Joomla社区生成器模块,并且在源代码中看到onAfterUserRegistration事件被触发。所以我试图为这个事件开发一个插件。这是我做了什么:为Joomla社区生成器开发插件

<?php 
defined('_JEXEC') or die('Restricted access'); 

jimport('joomla.plugin.plugin'); 

class plgUserRegistration extends JPlugin 
{ 
    function plgUserRegistration($subject, $config) 
    { 
     parent::__construct($subject, $config); 
    } 

    function onAfterUserRegistration() 
    { 
     //Do some stuff here ! 
    } 
} 

但我的代码不会被调用,我不能找出原因,如果有人因为任何线索!

+0

我一无所知的Joomla,但它似乎是,你只是在这里定义一个类。在大多数插件系统中,您需要实际注册插件,然后让插件订阅事件。我没有看到这两个步骤中的任何一个。他们需要Joomla吗? – Charles 2011-03-17 19:51:21

+0

是的,但需要通过后端来完成,而且我已经完成了。 – TrexXx 2011-03-17 20:18:29

回答

1

以下是一些建议:

  1. 检查插件是否启用。
  2. 插件组必须是User,请检查一下。
+0

除了Gaurav的回答,通过“启用插件”,他意味着你必须在插件表中创建一个数据库行。 – jdog 2011-03-29 07:44:58

0

有点晚了,但也许它可以帮助别人。你必须创建一个CB插件而不是Joomla插件。 您可以查阅CB插件框架API文档。

在你的PHP文件,你必须有这样的事情:

$_PLUGINS->registerFunction('onBeforeUserRegistration', 'pluginExampleBeforeUserRegistration'); 
/** 
* Example registration verify user method 
* Method is called before user data is stored in the database 
* @param array holds the core mambo user data 
* @param array holds the community builder user data 
* @param boolean false 
*/ 
function pluginExampleBeforeUserRegistration(&$user,&$cbUser) { 
    global $_POST, $_PLUGINS; 

    if ($_POST['username'] == $_POST['password']) { 
     $_PLUGINS->raiseError(0); 
     $_PLUGINS->_setErrorMSG("Password has to be different from username!"); 
    } 
    return true; 
} 

希望这有助于