Welcome Guest, Not a member yet? Register   Sign In
JSON-RPC Library
#12

[eluser]alexanderweiss[/eluser]
Great library!
For the people asking for more documentation/example code.

It works fine for me in this way:

Code:
<?php

class Pages extends Controller {

    function Pages()
    {
        parent::Controller();    
        $this->load->library('jsonrpc');
        $this->load->model('pagesmodel');
        $this->server = $this->jsonrpc->get_server();
        $methods = array(
          'contentList' => array('function' => 'Pages.contentList', 'summary' => 'Returns a contentList of pages.'),
          'updateContentListOrder' => array('function' => 'Pages.updateContentListOrder', 'summary' => 'Updates the order of pages and groups according to the passed array.')
    );
        $this->server->define_methods($methods);
        $this->server->set_object($this);
        $this->server->serve();
    }
    
    function index()
    {
    
    }
    
    function contentList()
    {  
      return $this->server->send_response($this->pagesmodel->get_all_pages());
    }
    
    function updateContentListOrder($order)
    {
       return $this->server->send_response($this->pagesmodel->update_order($order));
    }
}

I then do a JSON-RPC request like the following:
Code:
{"method":"contentList","params":null,"id":"gj5rqzrz"}

Or:
Code:
{"method":"updateContentListOrder","params":[{"id":"2","groupID":false},{"id":"7","groupID":"2"},{"id":"6","groupID":"2"},{"id":"5","groupID":"2"},{"id":"1","groupID":false},{"id":"8","groupID":"1"},{"id":"2","groupID":"1"},{"id":"4","groupID":"1"},{"id":"1","groupID":"1"}],"id":"gj5rxe12"}

In the first method my model simply returns an array containing object (result of a MySQL query).
For the second method the model takes an array of objects (as seen in the call) and returns true or false.

That's all there's to it. I hope it helps.


Messages In This Thread
JSON-RPC Library - by El Forum - 12-05-2008, 10:55 AM
JSON-RPC Library - by El Forum - 12-05-2008, 10:56 AM
JSON-RPC Library - by El Forum - 01-14-2009, 12:18 AM
JSON-RPC Library - by El Forum - 08-12-2009, 05:38 PM
JSON-RPC Library - by El Forum - 08-12-2009, 08:13 PM
JSON-RPC Library - by El Forum - 08-12-2009, 08:38 PM
JSON-RPC Library - by El Forum - 08-13-2009, 05:11 AM
JSON-RPC Library - by El Forum - 08-15-2009, 07:25 AM
JSON-RPC Library - by El Forum - 11-16-2009, 10:05 PM
JSON-RPC Library - by El Forum - 02-25-2010, 11:52 AM
JSON-RPC Library - by El Forum - 05-28-2010, 03:37 AM
JSON-RPC Library - by El Forum - 01-20-2011, 08:50 AM
JSON-RPC Library - by El Forum - 03-03-2011, 06:40 PM
JSON-RPC Library - by El Forum - 05-26-2011, 06:17 AM
JSON-RPC Library - by El Forum - 05-26-2011, 06:57 AM
JSON-RPC Library - by El Forum - 05-26-2011, 07:00 AM
JSON-RPC Library - by El Forum - 05-26-2011, 07:25 AM
JSON-RPC Library - by El Forum - 08-16-2011, 03:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB