I already have a Codeigniter based RESTful api service which performs basic CRUD operations to the mySQL database. And now I'm trying to make a control panel with angularJS and Restangular.
I make a POST request like this:
HTML:
<form ng-submit="addUser()">
<input type="text" name="name" ng-model="newUser.name" placeholder="Enter Your Name" />
<input type="text" name="fact" ng-model="newUser.fact" placeholder="Enter A Fact" />
<input class="pure-button" type="submit" value="Send" />
</form>
JS:
$scope.addUser = function ()
{
var newuser = $scope.newUser;
Restangular.one("user").post(newuser).then(function(data) {
console.log(data);
})
}
PHP (Using Codeigniter's inpu class):
$data = array(
'name' => $this->input->post('name'),
'fact' => $this->input->post('fact')
);
And then it writes $data array to the database. But in database, values are always 0, which means the $data['name'] and $data['fact'] are empty.
I think i should handle the data in a diffrent way in PHP but how can i do that? Or what is the type of POSTed data?
try
$data = file_get_contents("php://input");
$data = json_decode($data,true);
:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With