当在前端访问 Joomla 1.6 和 1.7 中的 com_users 组件时,应用程序会自动从“用户”组导入所有插件。显然,如果不想创建组件来简单地将一些变量传递给插件,这将非常有用。
好的。让我们让它更简单:
- 用户获得激活链接:http://example.com/index.php?option=com_users&task=edit&emailactivation=1&u=63&d077b8106=1并点击它。
- 当然,该组件将省略 emailactivation 和其他参数,仅显示“编辑配置文件表单”(或访客登录表单)。
- 然后 JApplication 从 'user' 组导入所有插件,这会触发 __constructors
基本上,使用插件的 __constructor 可以设置简单的操作,如下所示:
class plgUserAccountactivation extends JPlugin
{
public function __construct(& $subject, $config)
{
parent::__construct($subject, $config);
if(isset($_GET['emailactivation'])) {
// check token
// activate account, email or whatever
// redirect with message
}
}
}
哇!它可以工作,没有必要创建一个完整的 Controller 来处理一个简单的任务。
但是等一下...
- 在链接中将 index.php?option=com_users 更改为 index.php?option=com_user
- 让我们试试 Joomla 1.5...
嘿,嘿,什么都没发生 com_user 根本没有导入任何东西,也没有调用 __constructor。
我在 Joomla 1.5 中对此感到非常困扰,我不想编写整个组件。
如果有人有什么好主意,请告诉我。
编辑: 我通过以下形式发送链接解决了我的问题:
http:/example.com/index.php?option=com_user&task=logout&emailactivation=1&u=63&d077b8106=1
通过这种方式包含用户插件并执行 __constructors。但这太无聊了,因为 task=logout 并不真正鼓励点击链接。
最佳答案
1.5 的问题是事件更加有限。您有以下可用事件:Joomla 1.5 Plugin Events - User .因此,我想您的插件未启动。
如何将其制作成系统插件并检查 URL/请求属性中的激活情况?像这样的东西:
class plgSystemUseractiavation extends JPlugin {
function onAfterInitialise(){
$u = &JURI::getInstance();
$option = trim(strtolower($u->getVar('option')));
$emailactivation = trim(strtolower($u->getVar('emailactivation')));
if( strlen($option < 1) ){ // for SEF...
$option = trim(strtolower(JRequest::getString('option')));
}
$app =& JFactory::getApplication();
$appName = trim(strtolower($app->getName()));
if( $appName === 'site' ){
if( ( $option === 'com_users' ) || ( $option === 'com_user' ) ){
if( $emailactivation === '1' ){
// check token
// activate account, email or whatever
// redirect with message
}
}
}
}
}
关于php - Joomla 1.5 com_user 和导入用户插件,如 Joomla 1.6 及更高版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7236928/