Skip to content

Instantly share code, notes, and snippets.

@jorgeguberte
Created September 30, 2015 17:30
Show Gist options
  • Save jorgeguberte/48b575c360900c3a24e0 to your computer and use it in GitHub Desktop.
Save jorgeguberte/48b575c360900c3a24e0 to your computer and use it in GitHub Desktop.
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class Fornecedores extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('doctrine');
$this->em = $this->doctrine->em;
}
function index() {
}
function showAddView() {
$this->load->view('fornecedores/add');
}
function listView(){
$fornecedores = $this->em->getRepository('Entity\Fornecedor')->findAll();
$this->load->view('fornecedores/list', array('fornecedores'=>$fornecedores));
}
function add() {
#TODO: Sanitizar.
try {
if (!$this->input->post('inputCodigoFornecedor'))
throw new Exception('Falta Input Código');
if (!$this->input->post('inputNomeFornecedor'))
throw new Exception("Falta Input Nome");
if (!$this->input->post('inputDataCadastro'))
throw new Exception("Falta Input Data");
if(!$this->input->post('inputFornecedorAtivo'))
throw new Exception('Falta input ativo');
$codigo = $this->input->post('inputCodigoFornecedor');
$nome = $this->input->post('inputNomeFornecedor');
$date = new DateTime($this->input->post('inputDataCadastro'));
$ativo = $this->input->post('inputFornecedorAtivo');
/*
* Insertion routine
*/
$fornecedor = new Entity\Fornecedor;
$fornecedor->setCodigo($codigo);
$fornecedor->setNome($nome);
$fornecedor->setDataCadastro($date);
$fornecedor->setStatus(1); #TODO
$this->em->persist($fornecedor);
$this->em->flush();
redirect('fornecedores/listView/true');
} catch (Exception $ex) {
echo $ex->getMessage();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment