0

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

Jackhad
  • 411
  • 3
  • 8
  • 19
  • You forward your request to `$this->dispatcher->forward(array('controller' => "usertype", 'action' => 'index' ));`. What is for code is executed at `/usertype/index` ? – Timothy Apr 13 '16 at 12:55
  • the page should redirect to index page,thats why I wrote my $this->dispatcher->forward at controller page – Jackhad Apr 15 '16 at 04:20
  • As first fix your curl exec, you missing there "resource" $data = curl_exec($ch); Did your controller exist ? with action ? Do you forwarding to same module ? When controller with that action is in different module forwarding will not work. Try to use return $this->dispatcher->forward(array....); – Kamil Apr 19 '16 at 19:31
  • Thanks! Edited.Micro applications lacks of an internal dispatcher,So Tried $app->response->redirect("new/welcome")->sendHeaders();But no expected result – Jackhad Apr 20 '16 at 05:00

0 Answers0