简体   繁体   English

Joomla 2.5身份验证插件致命错误:在非对象上调用成员函数get()

[英]Joomla 2.5 authentication Plugin Fatal error: Call to a member function get() on a non-object

I wrote a simple authentication plugin that uses a SOAP webservice to check the username and the password. 我编写了一个简单的身份验证插件,该插件使用SOAP Web服务检查用户名和密码。 That works fine. 很好

I wanted to have some parameter like the SOAP password in the admin of joomla. 我想在joomla的管理员中输入一些参数,例如SOAP密码。 So I have added the params in the xml, it shows fine in the admin. 因此,我在xml中添加了参数,在admin中显示正常。 When I try to get the value of it the php, I get: 当我尝试获取php的价值时,我得到:

Fatal error: Call to a member function get() on a non-object 致命错误:在非对象上调用成员函数get()

So I compared with other authentication and I do it exactly the same way.... I do not understand why it is so. 因此,我将其与其他身份验证进行了比较,并以完全相同的方式进行了操作……。我不明白为什么会这样。

Here is the code of the Plugin: 这是插件的代码:

public function __construct() {
    $nusoap = JPATH_SITE . '/plugins/authentication/ers/nusoap/lib/nusoap.php';
    if (! file_exists ( $nusoap )){
                $response->error_message = "No such file";
        return;
            }
    require_once ($nusoap);

}



function onUserAuthenticate($credentials, $options, &$response)
{



        //Without defaults (the plugin crashes on the first get() bellow)
        $webservice = $this->params->get('webservice', '');
        $group      = $this->params->get('group', '');
        $whitepaw   = $this->params->get('whitepaw', '');



        JRequest::checkToken() or die( 'Invalid Token' );
        // For JLog
        $response->type = 'ERS SOAP Webservice';

            // MyCompany does not like blank passwords (So does Joomla ;))
    if (empty($credentials['password'])) {
        $response->status = JAuthentication::STATUS_FAILURE;
        $response->error_message = JText::_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');
        return false;
    }

    if (empty($credentials['username'])) {
        $response->status = JAuthentication::STATUS_FAILURE;
        $response->error_message = JText::_('Please enter a username');
        return false;
    }

           // Add a user to joomla
                function addJoomlaUser($name, $username, $password, $email, $group) {

                            $data = array(
                                "name"=>$name,
                                "username"=>$username,
                                "password"=>$password,
                                "password2"=>$password,
                                "email"=>$email,
                                "block"=>0,
                                "groups"=>array("1","2", $group) // the uer is added into the group "public" and "registered" as well as a group of the user's choice.

                            );

                            $user = clone(JFactory::getUser());
                            //Write to database
                            if(!$user->bind($data)) {
                                throw new Exception("Could not bind data. Error: " . $user->getError());
                            }
                            if (!$user->save()) {
                                throw new Exception("Could not save user. Error: " . $user->getError());
                            }

                        return $user->id;
                }


            // Pour supprimer le cache du web-service
            ini_set('soap.wsdl_cache_enabled', 0);

            // Nouveau Client SOAP
            try {

                // Nouvelle instance de la classe soapClient
                $client = new SoapClient($webservice, array('trace' => true));


                $username = $credentials['username'];
                $password = $credentials['password'];



                $result = $client->CheckLogin(array('whitepaw'=>$whitepaw, 'username'=>$username, 'password'=>$password));

                if($result->isInDB){


                        $name = $result->fname.' '.$result->lname;
                        $email = $result->email;

                        $response->error_message = $username.'<br>'.$password.'<br>'.$name.'<br>'.$email."<br><br>".
                                "<b>Request :</b><br>".htmlentities($client->__getLastRequest())."<br><br>".
                                "<b>RESPONSE :</b><br>".htmlentities($client->__getLastResponse())."<br><br>";

                        if(!$result->email == '' || empty ($result)) {
                            //Todo: check if the user is already in joomla db
                            $user_id = addJoomlaUser($name, $username, $password, $email,$group);
                            $response->status = JAuthentication::STATUS_SUCCESS;
                            //for testing purposes
                            $response->error_message = $user_id;
                      } else {
                           $response->error_message = "The webservice did not return data".$email.'did you see it?';

                       }

                } else {
                    $response->status = JAuthentication::STATUS_FAILURE;
                    $response->error_message = 'You do not have yet an account in <a href="http://my.ersnet.org">myers</a>. Please register.<br>';
                    $response->error_message .= $result->isInDB;

                }
                } catch (Exception $fault) {
                    $response->error_message = $fault->getMessage();
                }




}

} }

Since you have your own constructor, you need to call the parent constructor like this: 由于您拥有自己的构造函数,因此需要像这样调用父构造函数:

public function __construct(& $subject, $params = array()) {
    $nusoap = JPATH_SITE . '/plugins/authentication/ers/nusoap/lib/nusoap.php';
    if (! file_exists ( $nusoap )){
                $response->error_message = "No such file";
        return;
            }
    require_once ($nusoap);
    // call the parent constructor
    parent::__construct($subject, $params);
}

The parent constructor is where the $this->params object gets set, so if you don't call it then $this->params is never set. 父构造函数是设置$this->params对象的位置,因此,如果不调用它,则永远不会设置$this->params That's why you get the error saying params is not an object. 这就是为什么您会收到错误消息,指出params不是对象。

暂无
暂无

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

相关问题 Joomla 2.5模块问题,PHP致命错误在非对象上调用成员函数get() - Joomla 2.5 Module issues, PHP Fatal Error Call to a member function get() on a non-object 致命错误:在joomla2.5中的非对象上调用成员函数get() - Fatal error: Call to a member function get() on a non-object in joomla2.5 致命错误:在非对象Joomla上调用成员函数load() - Fatal error: Call to a member function load() on a non-object Joomla 致命错误:在非对象上调用成员函数get_results()(jQuery来自插件和WordPress) - Fatal error: Call to a member function get_results() on a non-object (jQuery From Plugin & WordPress) Joomla 2.5 PHP错误:致命错误:在第338行的com_upman / models / upman.php中的非对象上调用成员函数getUserStateFromRequest() - Joomla 2.5 PHP error: Fatal error: Call to a member function getUserStateFromRequest() on a non-object in com_upman/models/upman.php on line 338 全新安装后,Joomla 2.5.11错误:致命错误:在非对象上调用成员函数setDebug() - Joomla 2.5.11 error after fresh install: Fatal error: Call to a member function setDebug() on a non-object 致命错误:当它是一个对象时,调用非对象上的成员函数 - Fatal Error: Call to member function on non-object when it is an object 错误致命错误:在非对象上调用成员函数insert() - Error Fatal error: Call to a member function insert() on a non-object 致命错误:在非对象错误上调用成员函数prepare() - Fatal error: Call to a member function prepare() on a non-object ERROR 致命错误:在非对象错误上调用成员函数 query() - Fatal error: Call to a member function query() on a non-object Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM