I have the following class in php:
class Corretor
{
private $id;
private $nome;
private $registro;
private $email;
private $senha;
function __construct() {}
/* Getters e Setters*/
}
And in my html code, I have this javascript code:
$(document).on("click", "#btn_cadastra_corretor", function(e){
e.preventDefault();
var email = $('#box_corretor_email').val();
var senha = $('#box_corretor_senha').val();
var nome = $('#box_corretor_nome').val();
var registro = $('#box_corretor_registro').val();
$.ajax({
type: 'GET',
dataType: 'json',
data:{ categoria: '9', email: email, senha: senha, nome: nome, registro: registro },
url: 'http://localhost:8080/servidor/index.php',
success: function(resposta){
if (resposta)
{
alert("Conta cadastrada com sucesso!");
}
else
{
alert("Nao foi possível cadastrar!");
}
},
error: function (a, b, c){
alert("ERRO: " + a + " : " + b + " : " + c);
}
});
In php, I have several options that are accessed redirected by category - via a switch
-. The option that makes the registration is:
case 9: /* CATEGORIA 9 - Cadastra o corretor */
$corretor = new Corretor();
$corretor->setEmail($_GET['email']);
$corretor->setNome($_GET['nome']);
$corretor->setRegistro($_GET['registro']);
$corretor->setSenha($_GET['senha']);
echo json_encode($operacao->CadastraCorretor($corretor), JSON_PRETTY_PRINT);
break;
And in the operation class, I have the following code to register:
function CadastraCorretor(Corretor $corretor)
{
try
{
$stmt = Conexao::getInstance()->prepare('INSERT INTO corretor (nome, registro, email, senha, data_cadastro) VALUES (:nome, :registro, :email, :senha, :data_cadastro)');
$stmt->execute(array(
':nome' => $corretor->getNome(),
':registro' => $corretor->getRegistro(),
':email' => $corretor->getEmail(),
':senha' => $corretor->getSenha(),
':data_cadastro' => implode("-",array_reverse(explode("/", date("d/m/Y"))))
));
if ($stmt->rowCount() > 0)
{
return true;
}
return false;
}
catch (PDOException $e)
{
throw new Exception($e->getMessage());
}
}
What I want to know is if I have to send an object of the javascript itself, without having to set the properties, as is happening in the third code.