Joomla 3.0 使用 php 脚本注册用户 [英] Joomla 3.0 Register user with php script

查看:11
本文介绍了Joomla 3.0 使用 php 脚本注册用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索并找到了一种使用 JUser 执行此操作的方法,但是当我尝试该脚本时,它说找不到包含文件,并且它在服务器上不存在.我不知道 Joomla 3.0 是否有所不同,所以我寻求帮助.这是我试过的脚本:

I've searched and found a way to do this with JUser but when I try the script it says an include file can't be found and it doesn't exist on the server. I don't know if this is different for Joomla 3.0 so I was asking for help. Here's the script I tried:

<?php
   define( '_JEXEC', 1 );
   define('JPATH_BASE', dirname(__FILE__) );
   define( 'DS', DIRECTORY_SEPARATOR );
   /* Required Files */
   require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
   require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

   $app = JFactory::getApplication('site');
   $app->initialise();
   require_once JPATH_ROOT.DS.'components'.DS.'com_users'.DS.'models'.DS.'registration.php';
   require_once JPATH_ROOT.DS.'libraries'.DS.'joomla'.DS.'application'.DS.'component'.DS.'helper.php';
   $model = new UsersModelRegistration();
   jimport('joomla.mail.helper');
   jimport('joomla.user.helper');

   $username = 'jimporttest';
   $name = 'J Port2';
   $email = 'test @ mail.com';
   $password = 'test';
   $data = array( 'username' => $username,
             'name' => $name,
             'email1' => $email,
             'password1' => $password, // First password field
             'password2' => $password, // Confirm password field
             'block' => 0 );
   echo $model->register($data);
?>

推荐答案

您必须在 require_once 子句中使用 JPATH_BASE(您正在使用未定义的 JPATH_BASE_ROOT).同样在 JOOMLA 3.0 helper.php 它不在那个位置.

you have to use the JPATH_BASE in the require_once clause (you are using JPATH_BASE_ROOT which is not defined). Also in JOOMLA 3.0 the helper.php it is not in that position.

试试这个代码:

<?php
         define( '_JEXEC', 1 );
         define('JPATH_BASE', dirname(__FILE__) );
         define( 'DS', DIRECTORY_SEPARATOR );
         /* Required Files */
         require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
         require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

         $app = JFactory::getApplication('site');
         $app->initialise();
         require_once(JPATH_BASE.DS.'components'.DS.'com_users'.DS.'models'.DS.'registration.php';
        //not necessary
        //require_once(JPATH_BASE.DS.'libraries'.DS.'joomla'.DS.'application'.DS.'component'.DS.'helper.php';
         $model = new UsersModelRegistration();
         jimport('joomla.mail.helper');
         jimport('joomla.user.helper');

         $username = 'jimporttest';
         $name = 'J Port2';
         $email = 'test @ mail.com';
         $password = 'test';
         $data = array( 'username' => $username,
         'name' => $name,
         'email1' => $email,
         'password1' => $password, // First password field
         'password2' => $password, // Confirm password field
         'block' => 0 );
          echo $model->register($data);
  ?>

我已经在我的 joomla 3.0 安装中尝试过,它可以工作.

I've tried that in my joomla 3.0 installation and it works.

安德里亚

这篇关于Joomla 3.0 使用 php 脚本注册用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆