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,'https://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();
curl_close($ch);
print_r($data); // Here not printing the output!!
$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; } // Create a response $response = new Response();
// Check if the insertion was successful
if ($usertype->save() == true) {
// Change the HTTP status
$response->setStatusCode(201, "Created");
$usertype->user_type_id = $usertype->user_type_id;
$response->setJsonContent(
array(
'status' => 'OK',
'data' => $usertype
)
);
} else {
// Change the HTTP status
$response->setStatusCode(409, "Conflict");
// Send errors to the client
$errors = array();
foreach ($status->getMessages() as $message) {
$errors[] = $message->getMessage();
}
$response->setJsonContent(
array(
'status' => 'ERROR',
'messages' => $errors
)
);
}
return $response;
});
Using Curl the the values are posting fine and inserting but its not redirecting to my controller and not showing my index page .it jut 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