Im trying a application with phalcon and all the operations by web service .So Using Micro application for RestFul services.
See below my code: Usertypecontroller.php
public function createAction()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_setopt($ch,CURLOPT_URL,'http://localhost/xxx/yyy/api/usertype');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
$data = curl_exec($sh);
curl_close($ch);
$this->dispatcher->forward(array(
'controller' => "usertype",
'action' => 'index'
));
}
myrestAPI index.php file
$app->post('/api/usertype', function () use ($app) {
$usertype = new Usertype();
$usertype->name = $this->request->getPost("name");
$usertype->status = $this->request->getPost("status");
$usertype->createdon = $this->request->getPost("createdon");
$usertype->updateon = $this->request->getPost("updateon");
if (!$usertype->save()) {
foreach ($usertype->getMessages() as $message) {
$this->flash->error($message);
}
return;
}
return json_encode(
array(
'status' => 'OK',
'data' => $usertype
)
);
});
Using Curl the the values are posting fine and inserting but its not redirecting to my controller and not showing my index page .it just stops at my Curl and displaying
{"status":"OK","data":{"user_type_id":"71","name":"zczxc","status":"1"}}
I have tried with CURLOPT_RETURNTRANSFER and CURLOPT_FOLLOWLOCATION configs but nothing works.Anybody can help me would be grateful.Thanks