0
Hello!
I have the following controller at the angle:
myApp.controller('cadastrarClienteController', function($scope, $http){
$scope.cadastrarCliente = function () {
$cliente = {
CliNome: $scope.cli_nome,
CliTelefone: $scope.cli_telefone,
CliEmail: $scope.cli_email,
CliDescricao: $scope.cli_descricao
};
var response = $http({
method: "post",
url: baseUrl + "/index.php/Clientes/create",
data: JSON.stringify($cliente),
dataType: "json"
});
return response;});
It’s right the way I’m working?
create no php
public function create() {
if ($this->method == 'POST') {
$var = json_decode($_POST['cliente']);
var_dump($var);
/*$nome = $this->input->post('cli_nome');
$descricao = $this->input->post('cli_descricao');
$telefone = $this->input->post('cli_telefone');
$email = $this->input->post('cli_email');
$data = array(
'cli_nome' => $nome,
'cli_descricao' => $descricao,
'cli_telefone' => $telefone,
'cli_email' => $email,
);
$res = $this->clientes_model->create_cliente($data);*/
}
}
I don’t know what exactly to do inside this if. That is, how to "take" the data that comes by POST sent by angular.
is in the response that returns that worked?
Thank you
If you are coming by POST, have you ever tried to pick up using the $_POST['<variavel>'] ? What would go to php would be a Json, so you can try to catch it using json_decode.
– Rodrigo Tognin
make a
json_decodeand then a$_POST?– novato
In this case, try the following: $var = json_decode($_POST['client']); Then var_dump $var to see what appears.
– Rodrigo Tognin
I tried but it didn’t work out.. I changed the question to show how I’m doing it
– novato