我正在研究<div class="col-md-8">
<div class="row">
<div class="col-md-3">
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
</div>
<div class="col-md-3">
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
</div>
<div class="col-md-3">
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
</div>
<div class="col-md-3">
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
<p>Content goes here</p>
</div>
</div>
</div>
<div class="col-md-4">
<p>Right Sitebar content goses herpe</p>
<p>Right Sitebar content goses herpe</p>
<p>Right Sitebar content goses herpe</p>
<p>Right Sitebar content goses herpe</p>
<p>Right Sitebar content goses herpe</p>
<p>Right Sitebar content goses herpe</p>
<p>Right Sitebar content goses herpe</p>
</div>
的REST API。在我的localhost上工作得很好。当我将代码转移到cakephp
机器的实时服务器时,突然全部停止工作。虽然我的网站工作正常。
在调试时我发现AWS EC2 Ubuntu
为空。
这是我的代码
$_POST
我在 AppController.php
中允许我的控制器 public function add() { //die('dsafs');
$this->autoRender = false;
$this->layout = false;
// $this->loadModel('User');
$entityBody = file_get_contents('php://input');
pr($entityBody);
if ($this->request->is('post')) {
$this->User->set($this->request->data);
if ($this->User->validates($this->request->data)) {
if ($this->User->saveAll($this->request->data)) {
$response = array('status' => 'success', 'message' => 'Thank you for registering with us. Please check your e-mail inbox as your e-mail confirmation has just been sent.');
} else {
$response = array('status' => 'failed', 'message' => 'There might be some error. Please try again');
}
} else {
$response = array('status' => 'failed', 'message' => array_values($this->User->validationErrors));
}
echo str_replace(array('[', ']'), '', htmlspecialchars(json_encode($response), ENT_NOQUOTES));
// print_r($response);
}else{
echo "you are not authorised";
}
exit();
}
并在 routes.php
中添加路由 function beforeFilter() {
//pr($this->params);die;
if (in_array($this->params['controller'], array('api'))) {
// For RESTful web service requests, we check the name of our contoller
$this->Auth->allow();
// this line should always be there to ensure that all rest calls are secure
// $this->Security->requireSecure();
// $this->Security->unlockedActions = array('edit', 'delete', 'add', 'view');
} else {
$this->_defaultSettings();
}
}
以下是我的回复。
Router::mapResources('api');
Router::parseExtensions();
如果您需要其他任何东西,请告诉我。
答案 0 :(得分:0)
您可以使用file_get_contents('php:// input')从AJAX请求中获取数据。但是如果你想从POSTMAN发送数据,那么你需要使用$ _POST来获取数据。