Ejemplo n.º 1
0
<?php

try {
    $conexao = new \PDO("mysql:host=127.0.0.1;dbname=crud", "root", "root");
} catch (Exception $e) {
    echo 'Não foi possível conectar ao banco!';
}
require 'ProdutoService.php';
require 'ProdutoEntity.php';
if ($_POST) {
    $produto = new ProdutoEntity();
    $produto->setNome($_POST['nome'])->setCategoria($_POST['categoria']);
    $service = new ProdutoService($conexao, $produto);
    $products = $service->insert();
    header("Location:http://127.0.0.1:8080/");
}
?>
<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <title>CRUD</title>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
    </head>
    <body>
        <div class="row">
            <div class="col-md-3">
                <ul class="nav">
Ejemplo n.º 2
0
try {
    $conexao = new \PDO("mysql:host=127.0.0.1;dbname=crud", "root", "root");
} catch (Exception $e) {
    echo 'Não foi possível conectar ao banco!';
}
require 'ProdutoService.php';
require 'ProdutoEntity.php';
if ($_GET) {
    $produto = new ProdutoEntity();
    $service = new ProdutoService($conexao, $produto);
    $products = $service->find($_GET['id']);
}
if ($_POST) {
    $produto = new ProdutoEntity();
    $produto->setId($_POST['id'])->setNome($_POST['nome'])->setCategoria($_POST['categoria']);
    $service = new ProdutoService($conexao, $produto);
    $products = $service->update();
    header("Location:http://127.0.0.1:8080/");
}
?>
<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <title>CRUD</title>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
    </head>
    <body>
Ejemplo n.º 3
0
try {
    $conexao = new \PDO("mysql:host=127.0.0.1;dbname=crud", "root", "root");
} catch (Exception $e) {
    echo 'Não foi possível conectar ao banco!';
}
require 'ProdutoService.php';
require 'ProdutoEntity.php';
$produto = new ProdutoEntity();
$produto->setNome('Bola Quadrada')->setId(1)->setCategoria('Brinquedo');
$service = new ProdutoService($conexao, $produto);
$products = $service->listar();
if ($_GET && ($_GET['action'] = 'delete')) {
    $produto = new ProdutoEntity();
    $produto->setId($_GET['id']);
    $service = new ProdutoService($conexao, $produto);
    $products = $service->delete();
    header("Location:http://127.0.0.1:8080/");
}
?>
<!DOCTYPE html>
<html lang="pt-br">
    <head>
        <title>CRUD</title>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
    </head>
    <body>