重定向表单微应用程序到Phalcon控制器不工作

时间:2016-04-13 09:59:28

标签: redirect curl phalcon

我正在尝试使用phalcon的应用程序和Web服务的所有操作。所以使用Micro应用程序进行RestFul服务。

见下面我的代码: 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文件

$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
    )
    );
}); 

使用Curl,这些值可以正常发布并插入但不会重定向到我的控制器而不显示我的索引页面。只是停在我的Curl并显示

{"status":"OK","data":{"user_type_id":"71","name":"zczxc","status":"1"}}

我尝试使用CURLOPT_RETURNTRANSFER和CURLOPT_FOLLOWLOCATION配置,但没有任何效果。任何人都可以帮助我,我将不胜感激。谢谢

0 个答案:

没有答案