I have the following tabela
, controller
and model
, I want to get what is int
as int
, not string
.
Note that when the item is retrieved, the int
field is enclosed in quotation marks. How do I recover the data correctly?
Table
DROP TABLE IF EXISTS 'tbl_banco';
CREATE TABLE IF NOT EXISTS 'tbl_banco' (
'id' INT(11) NOT NULL AUTO_INCREMENT,
'codigo' VARCHAR(5) NOT NULL,
'nome' VARCHAR(255) NOT NULL,
'assessoria_id' INT(11) NOT NULL,
'dt_cadastro' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
'dt_atualizacao' TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
'situacao' TINYINT(1) NULL DEFAULT NULL,
PRIMARY KEY ('id'))
ENGINE = InnoDB
DEFAULT CHARSET = utf8;
Controller
//Função Obter Banco por ID
public function obter($id)
{
if ($id == 0)
{
$id = $id;
$dados = $this->banco->json_array($id);
echo json_encode($dados);
}
else
{
$dados = $this->banco->obter($id);
echo json_encode($dados);
}
}
Model
/*** Obter por ID ***/
public function obter($id)
{
$this->db->from($this->tbl_banco);
$this->db->where('id',$id);
$query = $this->db->get();
return $query->row_array();
}
Ajax
function obter(id, acao) {
var ret;
$.ajax({
type: 'GET',
async: false,
contentType: 'application/json',
url : "banco/obter/" + id + "/" + acao,
success: (function (obj) {
_obj = JSON.parse(obj);
_obj_banco = _obj;
objeto_form();
ret = true;
}),
error: (function (erro) {
trata_erro_ajax(erro);
ret = false;
})
});
return ret;
}