Welcome Guest, Not a member yet? Register   Sign In
Creating a new library; Needs the XMLRPC library to work.. help?
#1

[eluser]WoolyG[/eluser]
Hi all,

I'm creating a new library, and need to utilise the existing XMLRPC library for it to work.

After calling the new library, when I try to call
Code:
$this->mylibraryclass->send_request($method, $request_array);

I get this (see italicised text):

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Mylibraryclass::$xmlrpc
Filename: libraries/mylibraryclass.php
Line Number: 63


Here's the code:
Code:
class Mylibraryclass {


    const VERSION           = "0.1";
    const PLATFORM          = "web";
    const HARDWARE_VERSION  = "1.0";
    const SOFTWARE_VERSION  = "PHP";
    const APP_VERSION       = "1.0";
    const SERVER            = "http://myrpcserver.com/";
    const PORT              = 123456;



    public function __construct()
    {
        $CI =& get_instance();
        $CI->load->library('xmlrpc');
    }

    /**
     * @param $method
     * @param array $request_array
     * @return mixed
     */
    public function send_request($method, array $request_array)
    {

        /**
         * // Example from codeigniter user guide:
         *
         *  $this->load->library('xmlrpc'); // Autoloaded

        $this->xmlrpc->server('http://rpc.pingomatic.com/', 80);
        $this->xmlrpc->method('weblogUpdates.ping');

        $request = array('My Photoblog', 'http://www.my-site.com/photoblog/');
        $this->xmlrpc->request($request);

        if ( ! $this->xmlrpc->send_request())
        {
        echo $this->xmlrpc->display_error();
        }
         */

        //$this->xmlrpc->set_debug(TRUE);

        $this->xmlrpc->server(SERVER, PORT); // This is line 63
        $this->xmlrpc->method($method);
        $this->xmlrpc->request($request_array);
        $this->xmlrpc->send_request();


        if ( ! $this->xmlrpc->send_request())
        {
            $response = $this->xmlrpc->display_error();
        }
        else
        {
            $response = $this->xmlrpc->display_response();
        }

        return $response;

    }

}

Does this have something to do with the way I'm calling $this->xmlrpc->.. ? I've tried $CI->xmlrpc->.. to no avail.

All help is appreciated!

Thanks
WoolyG
#2

[eluser]WoolyG[/eluser]
Got it:

Code:
public function __construct()
    {
        $CI =& get_instance();
        $this->xmlrpc =& $CI->xmlrpc;
    }

then..

Code:
public function send_request($method, array $request_array)
    {

        

        $this->xmlrpc->server($server, $port);
        ..etc etc


    }



Hope this helps someone out in the future!
#3

[eluser]Aken[/eluser]
This is a more common way, allowing you to access any CI resource in your library, rather than assigning them individually to properties in your library.

Code:
<?php

class Mylibraryclass {

private $CI;

public function __construct()
{
  $this->CI =& get_instance();
  $this->CI->load->library('xmlrpc');
}

public function send_request()
{
  $this->CI->xmlrpc->server();
  // etc.
}
}
#4

[eluser]WoolyG[/eluser]
Ah nice one Aken - thanks for your input!




Theme © iAndrew 2016 - Forum software by © MyBB