How to use Phil Sturgeon's REST_SERVER |
[eluser]PaulDunn[/eluser]
This works: $test = $this->rest->get('property'); But this doesn't: $test = $this->rest->get('property', array('id' => '1'),'application/json'); Code: ============================================= It must be the query string causing the issue. Why doesnt it produce a URL like: http://localhost/index.php/api/property/id/1 That URL works fine the browser, cannot the client library use that instead of query strings? Also if I post xml to the server, how do I receive it in the server post function? Many thanks -Paul
[eluser]smilie[/eluser]
Hi, I do not know what it works like that ![]() Can't you use POST instead of GET? Just change Api from _get() to _post() (function) and ofcourse when calling from client. Regarding XML - no idea - never used it (not with REST - not with anything else) ![]() Maybe Phil will get here later on... Cheers, Smilie
[eluser]PaulDunn[/eluser]
So how would you retrieve json when you post it to the server? I think it will be the same process for XML. Cheers -Paul
[eluser]smilie[/eluser]
Paul, Here is an example of my code: Api (REST Server): Code: /** Controller which calls this Api function: Code: $this->load->library('rest', array('server' => REST_SERVER)); And the model which is called from Api function: Code: /** Instead of $result = "found" / "not found" you can also do: return TRUE / FALSE. You can also return arrays, in that case: Code: $return = array('result'=>'found'); and in the rest client: Code: if($this->input->post('email') != '' && $clientExists->result == "found") JSON returns object, so you access array with $data->array_key; In case of multiple array $data->array_key1['array_key2'] etc... Hope this helps :-) Cheers, Smilie
[eluser]madrico[/eluser]
is there a way to keep friendly-urls (via htaccess) and to use phil's restful server code? i had inquired about this on nettuts, but i haven't seen a reply. thanks in advance!!
[eluser]Ritesh Thumar[/eluser]
i want to fetch data from the database and want to send that data to mobile application using url. than how can i do that...????
[eluser]Phil Sturgeon[/eluser]
CodeIgniter by default will 404 if you try using a query string. You have to enable query string support before you can send GET parameters to CI or REST_Controller in this way. Once that is done, you can populate $this->get('id') with /users/method/id/1 or /users/method?id=1 $this->post() is used to fetch post data. $this->put() is used to fetch put data. $this->delete() is used to fetch delete data. You can send a body to REST_Server which will be contained in $this->request->body, but you will have to format that yourself. Hope this clears some stuff up!
[eluser]Davide Bellini[/eluser]
I found a small bug in Phil's REST_SERVER library ... at line 118, is not "statuc" but "status" : Code: $this->response( array('statuc' => false, 'error' => 'Only AJAX requests are accepted.'), 505 ); change to : Code: $this->response( array('status' => false, 'error' => 'Only AJAX requests are accepted.'), 505 ); Cheers
|
Welcome Guest, Not a member yet? Register Sign In |