简体   繁体   English

使用php在组件中创建Joomla 2.5用户

[英]Create Joomla 2.5 user in component with php

I'm currently developing a Joomla component and I'm totally stuck. 我目前正在开发Joomla组件,但完全陷入困境。 I want to add a bunch of users to Joomla 2.5 and I theoretically know how to do, but it doesn't work. 我想在Joomla 2.5中添加一堆用户,并且理论上我知道该怎么做,但这是行不通的。 More specific: The creation of passwords doesn't work as expected... 更具体的说:密码的创建无法按预期进行...

I'm using the following code to create the user's password : 我正在使用以下代码创建用户密码:

jimport('joomla.user.helper');

foreach($users as $user)
{
    $salt = JUserHelper::genRandomPassword(32);
    $crypt = JUserHelper::getCryptedPassword('foo', $salt);
    $password = $crypt.":".$salt;
}

If I try this code inside of the default view default.php it works as it should. 如果我在默认视图default.php中尝试此代码,它将按预期工作。 But if I use the same code inside of the controller it raises an Internal Server Error 500. 但是,如果我在控制器内部使用相同的代码,则会引发内部服务器错误500。

I don't understand why this doesn't work inside of the controller ... 我不明白为什么这在控制器内部不起作用...

Does someone know an answer? 有人知道答案吗?

Max 最高

Edit: It seems to be something about the foreach loop... The code works everywhere in the controller besides inside of the loop 编辑:这似乎是关于foreach循环...该代码除了在循环内在控制器中的所有地方都有效

I think good way is to observe the component com_adduserfrontend, more in details please observe file:components/com_adduserfrontend/views/adduserfrontend/tmpl/default.php 我认为不错的方法是观察组件com_adduserfrontend,更多细节请观察file:components / com_adduserfrontend / views / adduserfrontend / tmpl / default.php

The component set the password like this: 该组件按如下所示设置密码:

jimport( 'joomla.user.helper' );

$createpassword = createRandomPassword();

$password = getCryptedPassword($createpassword, $salt= '', $encryption= 'md5-hex', $show_encrypt=false);

$showpass = $createpassword;

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM