php register with angular js

0

Hello

I have the following controller in 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;});

Is the correct 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 do not know what exactly to do within that if . That is, how to "catch" the data that comes from POST sent by angular .

Is it in response that returns that worked?

Thank you

    
asked by anonymous 12.07.2016 / 02:39

2 answers

0

public function create($cli_nome, $cli_telefone, $cli_email, $cli_descricao) {
  /* Restante do código */
}

$cli_nome = $_POST["cli_nome"];
$cli_telefone = $_POST["cli_telefone"];
$cli_email = $_POST["cli_email"];
$cli_descricao = $_POST["cli_descricao"];

create($cli_nome, $cli_telefone, $cli_email, $cli_descricao);

Try to make the request and then send it to the function as a parameter.

    
13.07.2016 / 03:24
0

Good afternoon. Then I work with the code m API format and the front angular. First you will have to download and integrate to the link code.

It reads well how it works, it's simple really. After that, in the corner, you will set the url to send the request to the code.

In the code of the code, you will receive the information like this:

public function Formulario_post(){

    $nomeCliente = $this->post('cli_nome');
    //outras variáveis
    //segue para as validações e models

}

After processing the information and persisting or not in the database, you should return an Http code saying whether it worked or not. I advise you to read this Links also to understand.

I hope I have helped.

Oss!

    
18.07.2016 / 20:22