【问题标题】:Joomla PHP API get error messages for loggingJoomla PHP API 获取日志记录错误消息
【发布时间】:2017-05-03 09:18:12
【问题描述】:

我正在使用自己的脚本访问 Joomla PHP API,并且我已经编写了这个简单的注册函数,它是从移动应用程序调用的。

/* 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');

$model = new UsersModelRegistration();
jimport('joomla.mail.helper');
jimport('joomla.user.helper');
$language = JFactory::getLanguage();
$language->load('com_users', JPATH_SITE);

$username = JRequest::getVar('username', '', 'method', 'username');
$name = JRequest::getVar('name', '', 'method', 'name'); 
$email = JRequest::getVar('email', '', 'method', 'email'); 
$password = JRequest::getVar('password', '', 'method', 'password');

$data = array( 
'username' => $username,
'name' => $name,
'email1' => $email,
'password1' => $password, // First password field
'password2' => $password, // Confirm password field
'block' => 0);


if($model->register($data) == "useractivate") {
    print "Registered";
    //log successfull registration data maybe

}
else {
    print "Failed to register";
    //DEFINITELY LOG WHY IT FAILED
}

在其他部分,注册失败时有什么方法可以得到错误?

$model 是否包含与此相关的任何数据?

【问题讨论】:

    标签: php joomla joomla-extensions


    【解决方案1】:

    如果我说得对,那么您正在寻找 getErrors 函数。

    // Get the validation messages.
    $errors = $model->getErrors();
    
    // Push up to three validation messages out to the user.
    for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
    {
        if ($errors[$i] instanceof Exception)
        {
            $app->enqueueMessage($errors[$i]->getMessage(), 'warning');
        }
        else
        {
            $app->enqueueMessage($errors[$i], 'warning');
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-02-07
      • 2012-02-11
      • 2012-08-15
      • 1970-01-01
      • 2021-01-01
      • 2013-01-22
      • 2016-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多