getting error in rest api client

For programming and general questions on Zend Framework

getting error in rest api client

Postby happysidhu on Mon Apr 30, 2012 6:22 pm

HI!
i'm trying to do below client accessing
Code: Select all
require_once 'Zend/Rest/Client.php';
$client = new Zend_Rest_Client('http://zf.localhost/api.php');
$client->updatePage();
$client->apiKey('test');
$client->id(1);
$client->name('ss');
$client->headline('ss');
$client->description('d');
$client->content('d');

echo '<pre>';
print_r($client->get());
echo '</pre>';


here rest server code
Code: Select all
public function updatePage($apiKey, $id, $name, $headline, $description, $content)
{
    if(!$this->_validateKey($apiKey)) {
        return array('error' => 'invalid api key', 'status' => false);
    }
         
    // open the page
    $itemPage = new CMS_Content_Item_Page($id);
   
    // update it
    $itemPage->name = $name;
    $itemPage->headline = $headline;
    $itemPage->description = $description;
    $itemPage->content = $content;
   
    // save the content item
    $itemPage->save();
   
    // return the page as an array, which Zend_Rest will convert into the XML response
    return $itemPage->toArray();
}


when i access above client code i get below error
Code: Select all
Fatal error:  Uncaught exception 'Zend_Rest_Client_Result_Exception' with message 'REST Response Error: simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]:       ^' in C:\xampp\htdocs\owned\zf\library\Zend\Rest\Client\Result.php:61
Stack trace:
#0 C:\xampp\htdocs\owned\zf\library\Zend\Rest\Client.php(236): Zend_Rest_Client_Result->__construct(' <?xml version=...')
#1 C:\xampp\htdocs\owned\yuldi\test.php(14): Zend_Rest_Client->__call('get', Array)
#2 C:\xampp\htdocs\owned\yuldi\test.php(14): Zend_Rest_Client->get()
#3 {main}
  thrown in C:\xampp\htdocs\owned\zf\library\Zend\Rest\Client\Result.php on line 61


Please help me how to fix this.
happysidhu
 
Posts: 6
Joined: Wed Oct 27, 2010 11:53 am

need rest api help

Postby happysidhu on Tue May 08, 2012 6:09 pm

please help
happysidhu
 
Posts: 6
Joined: Wed Oct 27, 2010 11:53 am

Re: getting error in rest api client

Postby mkherlakian_zend on Tue May 08, 2012 7:06 pm

From the info you have posted it looks like part of your output needs encoding, simple_xml_string() can't load it, or there's some foreign output you don't necessarily see (and that you don't want) that ends up in the array.

I would however suggest you use Zend_Rest_Controller instead on Zend_Rest_Server as it is newer and more flexible:
http://framework.zend.com/manual/en/zend.controller.router.html#zend.rest.controller

and an example tutorial:
http://www.techchorus.net/create-restful-applications-using-zend-framework
User avatar
mkherlakian_zend
 
Posts: 88
Joined: Tue Jan 10, 2012 2:41 pm


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 13 guests