├── LICENSE ├── README.md ├── images ├── 0.png ├── 1.png ├── 10.png ├── 11.png ├── 12.png ├── 2.png ├── 3.png ├── 4.1.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png └── 9.png ├── mvc0 ├── README.md └── index.php ├── mvc1 ├── Controller.php ├── Model.php ├── README.md ├── index.php └── views │ └── index.php ├── mvc10 ├── .htaccess ├── App │ ├── Controllers │ │ ├── ClientController.php │ │ └── ProductController.php │ ├── Models │ │ ├── Client.php │ │ └── Product.php │ └── views │ │ ├── clients │ │ └── index.php │ │ ├── error │ │ └── index.php │ │ ├── products │ │ └── index.php │ │ └── templates │ │ ├── footer.php │ │ └── header.php ├── Core │ ├── Application.php │ ├── ErrorController.php │ ├── Model.php │ ├── README.md │ └── config.php ├── README.md ├── composer.json ├── db.sql ├── public │ ├── .htaccess │ ├── css │ │ └── style.css │ ├── img │ │ └── demo-image.png │ ├── index.php │ └── js │ │ └── application.js └── vendor │ ├── autoload.php │ └── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ └── autoload_static.php ├── mvc11 ├── .htaccess ├── App │ ├── Controllers │ │ ├── ClientController.php │ │ └── ProductController.php │ ├── Models │ │ ├── Client.php │ │ └── Product.php │ └── views │ │ ├── clients │ │ ├── index.php │ │ └── search.php │ │ ├── error │ │ └── index.php │ │ ├── products │ │ └── index.php │ │ └── templates │ │ ├── footer.php │ │ └── header.php ├── Core │ ├── Application.php │ ├── ErrorController.php │ ├── Model.php │ ├── README.md │ └── config.php ├── README.md ├── composer.json ├── db.sql ├── public │ ├── .htaccess │ ├── css │ │ └── style.css │ ├── img │ │ └── demo-image.png │ ├── index.php │ └── js │ │ └── application.js └── vendor │ ├── autoload.php │ └── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ └── autoload_static.php ├── mvc12 ├── .htaccess ├── App │ ├── Controllers │ │ ├── ClientController.php │ │ └── ProductController.php │ ├── Models │ │ ├── Client.php │ │ └── Product.php │ └── views │ │ ├── clients │ │ ├── index.php │ │ └── search.php │ │ ├── error │ │ └── index.php │ │ ├── products │ │ └── index.php │ │ └── templates │ │ ├── footer.php │ │ └── header.php ├── Core │ ├── Application.php │ ├── ErrorController.php │ ├── Model.php │ ├── README.md │ └── config.php ├── README.md ├── composer.json ├── db.sql ├── public │ ├── .htaccess │ ├── css │ │ └── style.css │ ├── img │ │ └── demo-image.png │ ├── index.php │ └── js │ │ └── application.js └── vendor │ ├── autoload.php │ └── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ └── autoload_static.php ├── mvc2 ├── Controller.php ├── Model.php ├── README.md ├── connection.php ├── db.sql └── index.php ├── mvc3 └── index.php ├── mvc4 ├── App │ ├── Controllers │ │ ├── ClientController.php │ │ └── ProductController.php │ ├── Models │ │ ├── Client.php │ │ └── Product.php │ └── views │ │ ├── clients │ │ └── index.php │ │ └── products │ │ └── index.php ├── Core │ ├── Model.php │ └── README.md ├── README.md ├── composer.json ├── db.sql ├── index.php └── vendor │ ├── autoload.php │ └── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ └── autoload_static.php ├── mvc5 ├── .htaccess ├── App │ ├── Controllers │ │ ├── ClientController.php │ │ └── ProductController.php │ ├── Models │ │ ├── Client.php │ │ └── Product.php │ └── views │ │ ├── clients │ │ └── index.php │ │ ├── error │ │ └── index.php │ │ ├── products │ │ └── index.php │ │ └── templates │ │ ├── footer.php │ │ └── header.php ├── Core │ ├── ErrorController.php │ ├── Model.php │ ├── README.md │ ├── Router.php │ └── config.php ├── README.md ├── composer.json ├── db.sql ├── public │ ├── .htaccess │ ├── css │ │ └── style.css │ ├── img │ │ └── demo-image.png │ ├── index.php │ └── js │ │ └── application.js └── vendor │ ├── autoload.php │ └── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ └── autoload_static.php ├── mvc6 ├── .htaccess ├── App │ ├── Controllers │ │ ├── ClientController.php │ │ └── ProductController.php │ ├── Models │ │ ├── Client.php │ │ └── Product.php │ └── views │ │ ├── clients │ │ └── index.php │ │ ├── error │ │ └── index.php │ │ ├── products │ │ └── index.php │ │ └── templates │ │ ├── footer.php │ │ └── header.php ├── Core │ ├── ErrorController.php │ ├── Model.php │ ├── README.md │ ├── Router.php │ └── config.php ├── README.md ├── composer.json ├── db.sql ├── public │ ├── .htaccess │ ├── css │ │ └── style.css │ ├── img │ │ └── demo-image.png │ ├── index.php │ └── js │ │ └── application.js └── vendor │ ├── autoload.php │ └── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ └── autoload_static.php ├── mvc7 ├── .htaccess ├── App │ ├── Controllers │ │ ├── ClientController.php │ │ └── ProductController.php │ ├── Models │ │ ├── Client.php │ │ └── Product.php │ └── views │ │ ├── clients │ │ ├── edit.php │ │ └── index.php │ │ ├── error │ │ └── index.php │ │ ├── products │ │ └── index.php │ │ └── templates │ │ ├── footer.php │ │ └── header.php ├── Core │ ├── ErrorController.php │ ├── Model.php │ ├── README.md │ ├── Router.php │ └── config.php ├── README.md ├── composer.json ├── db.sql ├── public │ ├── .htaccess │ ├── css │ │ └── style.css │ ├── img │ │ └── demo-image.png │ ├── index.php │ └── js │ │ └── application.js └── vendor │ ├── autoload.php │ └── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ └── autoload_static.php ├── mvc8 ├── .htaccess ├── App │ ├── Controllers │ │ ├── ClientController.php │ │ └── ProductController.php │ ├── Models │ │ ├── Client.php │ │ └── Product.php │ └── views │ │ ├── clients │ │ ├── edit.php │ │ └── index.php │ │ ├── error │ │ └── index.php │ │ ├── products │ │ └── index.php │ │ └── templates │ │ ├── footer.php │ │ └── header.php ├── Core │ ├── Application.php │ ├── ErrorController.php │ ├── Model.php │ ├── README.md │ └── config.php ├── README.md ├── composer.json ├── db.sql ├── public │ ├── .htaccess │ ├── css │ │ └── style.css │ ├── img │ │ └── demo-image.png │ ├── index.php │ └── js │ │ └── application.js └── vendor │ ├── autoload.php │ └── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ └── autoload_static.php ├── mvc9 ├── .htaccess ├── App │ ├── Controllers │ │ ├── ClientController.php │ │ └── ProductController.php │ ├── Models │ │ ├── Client.php │ │ └── Product.php │ └── views │ │ ├── clients │ │ └── index.php │ │ ├── error │ │ └── index.php │ │ ├── products │ │ └── index.php │ │ └── templates │ │ ├── footer.php │ │ └── header.php ├── Core │ ├── Application.php │ ├── ErrorController.php │ ├── Model.php │ ├── README.md │ └── config.php ├── README.md ├── composer.json ├── db.sql ├── public │ ├── .htaccess │ ├── css │ │ └── style.css │ ├── img │ │ └── demo-image.png │ ├── index.php │ └── js │ │ └── application.js └── vendor │ ├── autoload.php │ └── composer │ ├── ClassLoader.php │ ├── LICENSE │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ └── autoload_static.php ├── mvcx ├── Migrations │ ├── 20200415153724_produtos.php │ ├── 20200415153733_pedidos.php │ ├── ForeignKey │ ├── Migrations com Phinx │ ├── MigrationsCake3.pdf │ ├── ProdutosSeed.php │ └── seeds ├── README.md ├── pdox │ ├── .gitignore │ ├── .travis.yml │ ├── DOCS.md │ ├── LICENCE.md │ ├── README.md │ ├── composer.json │ ├── example.php │ ├── src │ │ ├── Cache.php │ │ ├── Pdox.php │ │ └── PdoxInterface.php │ └── tests │ │ ├── DeleteTest.php │ │ ├── InsertTest.php │ │ ├── JoinTest.php │ │ ├── SelectTest.php │ │ └── UpdateTest.php └── tracy-debug.md └── rotas ├── Router.php ├── Router2.php ├── Routes.md ├── mvc-router-inicial ├── README.md ├── mvc_router_inicial │ ├── .htaccess │ ├── README.md │ ├── composer.json │ ├── namespace.txt │ ├── projeto.txt │ ├── public │ │ ├── .htaccess │ │ └── index.php │ ├── src │ │ ├── Controller │ │ │ └── ClientesController.php │ │ ├── Model │ │ │ └── ClientesModel.php │ │ ├── View │ │ │ └── ClientesView.php │ │ ├── bootstrap.php │ │ └── config.php │ └── vendor │ │ ├── autoload.php │ │ └── composer │ │ ├── ClassLoader.php │ │ ├── LICENSE │ │ ├── autoload_classmap.php │ │ ├── autoload_namespaces.php │ │ ├── autoload_psr4.php │ │ ├── autoload_real.php │ │ └── autoload_static.php ├── mvc_router_inicial2 │ ├── .gitignore │ ├── .htaccess │ ├── README.md │ ├── composer.json │ ├── public │ │ ├── .htaccess │ │ ├── css │ │ │ └── custom.css │ │ └── index.php │ └── src │ │ ├── Controller │ │ └── ClientesController.php │ │ ├── Core │ │ ├── Model.php │ │ └── Router.php │ │ ├── Model │ │ └── ClientesModel.php │ │ ├── View │ │ └── ClientesView.php │ │ ├── bootstrap.php │ │ └── config.php └── mvc_router_inicial3 │ ├── .gitignore │ ├── .htaccess │ ├── README.md │ ├── composer.json │ ├── public │ ├── .htaccess │ └── index.php │ └── src │ ├── Controller │ ├── ClientesController.php │ └── ErrorController.php │ ├── Core │ ├── Model.php │ └── Router.php │ ├── Model │ └── ClientesModel.php │ ├── View │ └── ClientesView.php │ ├── bootstrap.php │ ├── config.php │ └── templates │ ├── _includes │ ├── footer.php │ └── header.php │ ├── clientes │ ├── add.php │ ├── edit.php │ └── index.php │ └── error │ └── index.php └── rota-simples ├── index.php └── views ├── 404.php ├── about.php └── index.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ribamar FS 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Criação de um aplicativo em PHP com MVC do "zero" 2 | 3 | ## Muito importante 4 | 5 | Requer o mod_rewrite habilitado e com apache funcionando. 6 | 7 | ## O exemplo mais simples que já vi. 8 | 9 | Do mínimo até algo usável para mostrar bons recursos que são utilizadoso nos grandes frameworks 10 | 11 | Em diversas fases, seguindo da inicial e seguindo em frente. 12 | 13 | ## Gratidão ao Panique 14 | Graças ao seu projeto mini3, consegui criar este projeto. 15 | https://github.com/panique/mini3 16 | 17 | ## Em várias fases 18 | 19 | - Faça o download para seu diretório web 20 | - Crie um banco de dados e importe o script db.sql 21 | - Ajuste o Core/config.php para o banco criado. Veja capturas das várias fases abaixo: 22 | 23 | Fase inicial sem banco, apenas com um array 24 | 25 | ![](images/0.png) 26 | 27 | ![](images/1.png) 28 | 29 | ![](images/2.png) 30 | 31 | ![](images/3.png) 32 | 33 | ![](images/4.png) 34 | 35 | ![](images/4.1.png) 36 | 37 | ![](images/5.png) 38 | 39 | ![](images/6.png) 40 | 41 | ![](images/7.png) 42 | 43 | ![](images/8.png) 44 | 45 | ![](images/9.png) 46 | 47 | ![](images/10.png) 48 | 49 | ![](images/11.png) 50 | 51 | ![](images/12.png) 52 | 53 | ## Licença 54 | 55 | MIT 56 | 57 | -------------------------------------------------------------------------------- /images/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/0.png -------------------------------------------------------------------------------- /images/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/1.png -------------------------------------------------------------------------------- /images/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/10.png -------------------------------------------------------------------------------- /images/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/11.png -------------------------------------------------------------------------------- /images/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/12.png -------------------------------------------------------------------------------- /images/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/2.png -------------------------------------------------------------------------------- /images/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/3.png -------------------------------------------------------------------------------- /images/4.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/4.1.png -------------------------------------------------------------------------------- /images/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/4.png -------------------------------------------------------------------------------- /images/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/5.png -------------------------------------------------------------------------------- /images/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/6.png -------------------------------------------------------------------------------- /images/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/7.png -------------------------------------------------------------------------------- /images/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/8.png -------------------------------------------------------------------------------- /images/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/images/9.png -------------------------------------------------------------------------------- /mvc0/README.md: -------------------------------------------------------------------------------- 1 | # Aplicativo em PHP usando MVC partindo do "zero" 2 | 3 | Este fase inicial começa com apenas o arquivo index.php, que contém uma classe Model com um array no lugar do banco de dados, uma classe Controller e a view mostrando o retorno do model. 4 | 5 | 6 | -------------------------------------------------------------------------------- /mvc0/index.php: -------------------------------------------------------------------------------- 1 | clients; 13 | } 14 | } 15 | 16 | class Controller { 17 | 18 | public function index() { 19 | $list = new Model(); 20 | $clients = $list->index(); 21 | 22 | return $clients; 23 | } 24 | } 25 | //Importante que a view não vá direto ao model, mas que receba dados do model através do controller 26 | // Original em 27 | // https://elias.praciano.com/2014/08/php-mvc-e-hello-world/ 28 | ?> 29 |
30 |

MVC Olá Mundo - 0

31 |

Lista de Clientes

32 | 33 | 34 | index(); 38 | 39 | for ($lin=0; $lin<4; $lin++) { 40 | print ''; 41 | for ($col=0; $col<3; $col++) { 42 | echo ''; 43 | } 44 | print ''; 45 | } 46 | 47 | ?> 48 |
CódigoNomeIdade
'.$clients[$lin][$col].'
49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /mvc1/Controller.php: -------------------------------------------------------------------------------- 1 | index(); 11 | 12 | require_once 'views/index.php'; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mvc1/Model.php: -------------------------------------------------------------------------------- 1 | clients; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mvc1/README.md: -------------------------------------------------------------------------------- 1 | # MVC Simples em PHP sem banco de dados 2 | 3 | ## Arquivos 4 | 5 | index.php 6 | Controller.php 7 | Model.php 8 | views/index.php 9 | 10 | ## Fluxo das informações 11 | 12 | Quando o index.php é chamado: 13 | 14 | - inclui o Controller.php 15 | - Instancia o Controller 16 | - Chama o método index() do mesmo 17 | 18 | O Controller é chamado: 19 | 20 | - Ele inclui o Model 21 | - Instancia o model 22 | - Chama seu método index(), que retorna o array $clients e armazena na variável $list; 23 | - Então o Controller inclui o index.php da view. 24 | 25 | Quando o Model é chamado 26 | 27 | - Ele define um array multi dimensional na variável $clients e insere 4 clientes, com código, nome e idade 28 | - Retorna em seu método index() este array 29 | - Este array é recebido pelo Controller 30 | 31 | Quando o index.php é chamado 32 | 33 | - Mostra algum texto explicativo na tela 34 | - Cria uma tabela HTML 35 | - Joga na tabela o resultado de um for trazendo o array $list, vindo do Controller, que recebeu do Model 36 | 37 | No caso a View recebe do Controller e não diretamente do Model, o que é uma boa prática. 38 | 39 | 40 | -------------------------------------------------------------------------------- /mvc1/index.php: -------------------------------------------------------------------------------- 1 | index(); 8 | 9 | 10 | -------------------------------------------------------------------------------- /mvc1/views/index.php: -------------------------------------------------------------------------------- 1 |
2 |

MVC Simples em PHP - 1

3 |

Sem banco de dados

4 | 5 |

Lista de clientes

6 | 7 | 8 | 9 | '; 13 | for ($col=0; $col<3; $col++) { 14 | echo ''; 15 | } 16 | print ''; 17 | } 18 | 19 | ?> 20 |
CódigoNomeIdade
'.$list[$lin][$col].'
21 |
22 | -------------------------------------------------------------------------------- /mvc10/.htaccess: -------------------------------------------------------------------------------- 1 | # This file is - if you set up MINI correctly - not needed. 2 | # But, for fallback reasons (if you don't route your vhost to /public), it will stay here. 3 | RewriteEngine on 4 | RewriteRule ^(.*) public/$1 [L] 5 | -------------------------------------------------------------------------------- /mvc10/App/Controllers/ProductController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once APP . 'views/templates/header.php'; 14 | require_once APP . 'views/products/index.php'; 15 | require_once APP . 'views/templates/footer.php'; 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mvc10/App/Models/Client.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM clients order by id desc"); 10 | $executa = $stmte->execute(); 11 | $clients = $stmte->fetchall(); 12 | 13 | return $clients; 14 | } 15 | 16 | public function add($nome, $idade) 17 | { 18 | $sql = "INSERT INTO clients (nome, idade) VALUES (:nome, :idade)"; 19 | $query = $this->pdo->prepare($sql); 20 | $parameters = array(':nome' => $nome, ':idade' => $idade); 21 | $query->execute($parameters); 22 | } 23 | 24 | public function delete($id) 25 | { 26 | $sql = "DELETE FROM clients WHERE id = :id"; 27 | $query = $this->pdo->prepare($sql); 28 | $parameters = array(':id' => $id); 29 | $query->execute($parameters); 30 | } 31 | 32 | public function edit($id) 33 | { 34 | $sql = "SELECT id, nome, idade FROM clients WHERE id = :id LIMIT 1"; 35 | $query = $this->pdo->prepare($sql); 36 | $parameters = array(':id' => $id); 37 | $query->execute($parameters); 38 | return ($query->rowCount() ? $query->fetch() : false); 39 | } 40 | 41 | public function update($nome, $idade, $id) 42 | { 43 | $sql = "UPDATE clients SET nome = :nome, idade = :idade WHERE id = :id"; 44 | $query = $this->pdo->prepare($sql); 45 | $parameters = array(':nome' => $nome, ':idade' => $idade, ':id' => $id); 46 | 47 | $query->execute($parameters); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /mvc10/App/Models/Product.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM products order by id"); 10 | $executa = $stmte->execute(); 11 | $products = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 12 | 13 | return $products; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mvc10/App/views/error/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

Esta é a página de erros. Verifique que seu controller ou method não existem.

5 |
6 | -------------------------------------------------------------------------------- /mvc10/App/views/products/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | Você está na view: App/views/products/index.php 4 |

5 | 6 |

Lista de produtos

7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
IdNomePreço
27 |
28 | -------------------------------------------------------------------------------- /mvc10/App/views/templates/footer.php: -------------------------------------------------------------------------------- 1 |

2 |
3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mvc10/App/views/templates/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MVC 10 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |

Mini MVC 10

16 |

(Com Autoload, PSR-4 e Rotas)

17 |
18 |
19 | Clientes    20 | Produtos 21 |
22 |
23 | -------------------------------------------------------------------------------- /mvc10/Core/ErrorController.php: -------------------------------------------------------------------------------- 1 | host = HOST; 15 | $this->user = USER; 16 | $this->pass = PASS; 17 | $this->db = DB; 18 | $dsn = 'mysql:host='.$this->host.';dbname='.$this->db; 19 | 20 | try { 21 | // Para que usemos as variáveis como objeto ($client->id) e mostre mais detalhes nas mensagens de erro 22 | // A barra antes do PDO (\PDO) é para indicar que estamos usando ele em seu próprio namespace e não é uma classe do nosso namespace 23 | $options = array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING); 24 | $this->pdo = new \PDO($dsn, $this->user, $this->pass, $options ); 25 | 26 | return $this->pdo; 27 | 28 | } catch (\PDOException $e) { 29 | print "Error!: " . $e->getMessage() . "
"; 30 | die(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mvc10/Core/README.md: -------------------------------------------------------------------------------- 1 | # Core 2 | 3 | Esta pasta abriga as classes básicas, ou seja, as classes pais. 4 | 5 | As classes da pasta App são filhas destas daqui e as extendem. 6 | 7 | Em App poderemos ter várias classes filhas de Model: ClientModel, ProductModel, etc. 8 | 9 | 10 | -------------------------------------------------------------------------------- /mvc10/Core/config.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/composer/InstalledVersions.php', 10 | ); 11 | -------------------------------------------------------------------------------- /mvc10/vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/Core'), 10 | 'App\\' => array($baseDir . '/App'), 11 | ); 12 | -------------------------------------------------------------------------------- /mvc10/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Core\\' => 5, 13 | ), 14 | 'A' => 15 | array ( 16 | 'App\\' => 4, 17 | ), 18 | ); 19 | 20 | public static $prefixDirsPsr4 = array ( 21 | 'Core\\' => 22 | array ( 23 | 0 => __DIR__ . '/../..' . '/Core', 24 | ), 25 | 'App\\' => 26 | array ( 27 | 0 => __DIR__ . '/../..' . '/App', 28 | ), 29 | ); 30 | 31 | public static $classMap = array ( 32 | 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 33 | ); 34 | 35 | public static function getInitializer(ClassLoader $loader) 36 | { 37 | return \Closure::bind(function () use ($loader) { 38 | $loader->prefixLengthsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixLengthsPsr4; 39 | $loader->prefixDirsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixDirsPsr4; 40 | $loader->classMap = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$classMap; 41 | 42 | }, null, ClassLoader::class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mvc11/.htaccess: -------------------------------------------------------------------------------- 1 | # This file is - if you set up MINI correctly - not needed. 2 | # But, for fallback reasons (if you don't route your vhost to /public), it will stay here. 3 | RewriteEngine on 4 | RewriteRule ^(.*) public/$1 [L] 5 | -------------------------------------------------------------------------------- /mvc11/App/Controllers/ProductController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once APP . 'views/templates/header.php'; 14 | require_once APP . 'views/products/index.php'; 15 | require_once APP . 'views/templates/footer.php'; 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mvc11/App/Models/Product.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM products order by id"); 10 | $executa = $stmte->execute(); 11 | $products = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 12 | 13 | return $products; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mvc11/App/views/clients/search.php: -------------------------------------------------------------------------------- 1 | '; 4 | print '

Registro(s) encontrado(s)

'; 5 | 6 | if(count($clients) > 0){ 7 | ?> 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | '; 18 | print ''; 19 | print ''; 20 | } 21 | echo "
IDNomeIdade
'.$row->id.''.$row->nome.''.$row->idade.'
"; 22 | }else{ 23 | print '

Nenhum Registro encontrado!

'; 24 | } 25 | } 26 | exit; 27 | ?> 28 | -------------------------------------------------------------------------------- /mvc11/App/views/error/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

Esta é a página de erros. Verifique que seu controller ou method não existem.

5 |
6 | -------------------------------------------------------------------------------- /mvc11/App/views/products/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | Você está na view: App/views/products/index.php 4 |

5 | 6 |

Lista de produtos

7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
IdNomePreço
27 |
28 | -------------------------------------------------------------------------------- /mvc11/App/views/templates/footer.php: -------------------------------------------------------------------------------- 1 |

2 |
3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mvc11/App/views/templates/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MVC 11 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |

Mini MVC 11

16 |

(Com Autoload, PSR-4 e Rotas)

17 |
18 |
19 | Clientes    20 | Produtos 21 |
22 |
23 | -------------------------------------------------------------------------------- /mvc11/Core/ErrorController.php: -------------------------------------------------------------------------------- 1 | host = HOST; 15 | $this->user = USER; 16 | $this->pass = PASS; 17 | $this->db = DB; 18 | $dsn = 'mysql:host='.$this->host.';dbname='.$this->db; 19 | 20 | try { 21 | // Para que usemos as variáveis como objeto ($client->id) e mostre mais detalhes nas mensagens de erro 22 | // A barra antes do PDO (\PDO) é para indicar que estamos usando ele em seu próprio namespace e não é uma classe do nosso namespace 23 | $options = array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING); 24 | $this->pdo = new \PDO($dsn, $this->user, $this->pass, $options ); 25 | 26 | return $this->pdo; 27 | 28 | } catch (\PDOException $e) { 29 | print "Error!: " . $e->getMessage() . "
"; 30 | die(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mvc11/Core/README.md: -------------------------------------------------------------------------------- 1 | # Core 2 | 3 | Esta pasta abriga as classes básicas, ou seja, as classes pais. 4 | 5 | As classes da pasta App são filhas destas daqui e as extendem. 6 | 7 | Em App poderemos ter várias classes filhas de Model: ClientModel, ProductModel, etc. 8 | 9 | 10 | -------------------------------------------------------------------------------- /mvc11/Core/config.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/composer/InstalledVersions.php', 10 | ); 11 | -------------------------------------------------------------------------------- /mvc11/vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/Core'), 10 | 'App\\' => array($baseDir . '/App'), 11 | ); 12 | -------------------------------------------------------------------------------- /mvc11/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Core\\' => 5, 13 | ), 14 | 'A' => 15 | array ( 16 | 'App\\' => 4, 17 | ), 18 | ); 19 | 20 | public static $prefixDirsPsr4 = array ( 21 | 'Core\\' => 22 | array ( 23 | 0 => __DIR__ . '/../..' . '/Core', 24 | ), 25 | 'App\\' => 26 | array ( 27 | 0 => __DIR__ . '/../..' . '/App', 28 | ), 29 | ); 30 | 31 | public static $classMap = array ( 32 | 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 33 | ); 34 | 35 | public static function getInitializer(ClassLoader $loader) 36 | { 37 | return \Closure::bind(function () use ($loader) { 38 | $loader->prefixLengthsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixLengthsPsr4; 39 | $loader->prefixDirsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixDirsPsr4; 40 | $loader->classMap = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$classMap; 41 | 42 | }, null, ClassLoader::class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mvc12/.htaccess: -------------------------------------------------------------------------------- 1 | # This file is - if you set up MINI correctly - not needed. 2 | # But, for fallback reasons (if you don't route your vhost to /public), it will stay here. 3 | RewriteEngine on 4 | RewriteRule ^(.*) public/$1 [L] 5 | -------------------------------------------------------------------------------- /mvc12/App/Controllers/ProductController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once APP . 'views/templates/header.php'; 14 | require_once APP . 'views/products/index.php'; 15 | require_once APP . 'views/templates/footer.php'; 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mvc12/App/Models/Product.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM products order by id"); 10 | $executa = $stmte->execute(); 11 | $products = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 12 | 13 | return $products; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mvc12/App/views/clients/search.php: -------------------------------------------------------------------------------- 1 | '; 4 | print '

Registro(s) encontrado(s)

'; 5 | 6 | if(count($clients) > 0){ 7 | ?> 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | '; 18 | print ''; 19 | print ''; 20 | } 21 | echo "
IDNomeIdade
'.$row->id.''.$row->nome.''.$row->idade.'
"; 22 | }else{ 23 | print '

Nenhum Registro encontrado!

'; 24 | } 25 | } 26 | exit; 27 | ?> 28 | -------------------------------------------------------------------------------- /mvc12/App/views/error/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

Esta é a página de erros. Verifique que seu controller ou method não existem.

5 |
6 | -------------------------------------------------------------------------------- /mvc12/App/views/products/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | Você está na view: App/views/products/index.php 4 |

5 | 6 |

Lista de produtos

7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
IdNomePreço
27 |
28 | -------------------------------------------------------------------------------- /mvc12/App/views/templates/footer.php: -------------------------------------------------------------------------------- 1 |

2 |
3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mvc12/App/views/templates/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MVC 12 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |

Simplest MVC - 12

16 |

(Com Autoload, PSR-4 e Rotas)

17 |
18 |
19 | Clientes    20 | Produtos 21 |
22 |
23 | -------------------------------------------------------------------------------- /mvc12/Core/ErrorController.php: -------------------------------------------------------------------------------- 1 | host = HOST; 15 | $this->user = USER; 16 | $this->pass = PASS; 17 | $this->db = DB; 18 | $dsn = 'mysql:host='.$this->host.';dbname='.$this->db; 19 | 20 | try { 21 | // Para que usemos as variáveis como objeto ($client->id) e mostre mais detalhes nas mensagens de erro 22 | // A barra antes do PDO (\PDO) é para indicar que estamos usando ele em seu próprio namespace e não é uma classe do nosso namespace 23 | $options = array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING); 24 | $this->pdo = new \PDO($dsn, $this->user, $this->pass, $options ); 25 | 26 | return $this->pdo; 27 | 28 | } catch (\PDOException $e) { 29 | print "Error!: " . $e->getMessage() . "
"; 30 | die(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mvc12/Core/README.md: -------------------------------------------------------------------------------- 1 | # Core 2 | 3 | Esta pasta abriga as classes básicas, ou seja, as classes pais. 4 | 5 | As classes da pasta App são filhas destas daqui e as extendem. 6 | 7 | Em App poderemos ter várias classes filhas de Model: ClientModel, ProductModel, etc. 8 | 9 | 10 | -------------------------------------------------------------------------------- /mvc12/Core/config.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/composer/InstalledVersions.php', 10 | ); 11 | -------------------------------------------------------------------------------- /mvc12/vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/Core'), 10 | 'App\\' => array($baseDir . '/App'), 11 | ); 12 | -------------------------------------------------------------------------------- /mvc12/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Core\\' => 5, 13 | ), 14 | 'A' => 15 | array ( 16 | 'App\\' => 4, 17 | ), 18 | ); 19 | 20 | public static $prefixDirsPsr4 = array ( 21 | 'Core\\' => 22 | array ( 23 | 0 => __DIR__ . '/../..' . '/Core', 24 | ), 25 | 'App\\' => 26 | array ( 27 | 0 => __DIR__ . '/../..' . '/App', 28 | ), 29 | ); 30 | 31 | public static $classMap = array ( 32 | 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 33 | ); 34 | 35 | public static function getInitializer(ClassLoader $loader) 36 | { 37 | return \Closure::bind(function () use ($loader) { 38 | $loader->prefixLengthsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixLengthsPsr4; 39 | $loader->prefixDirsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixDirsPsr4; 40 | $loader->classMap = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$classMap; 41 | 42 | }, null, ClassLoader::class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mvc2/Controller.php: -------------------------------------------------------------------------------- 1 | index(); 11 | 12 | require_once 'views/index.php'; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mvc2/Model.php: -------------------------------------------------------------------------------- 1 | query("SELECT * FROM clients order by id"); 11 | $executa = $stmte->execute(); 12 | $clients = $stmte->fetchall(PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 13 | 14 | return $clients; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mvc2/README.md: -------------------------------------------------------------------------------- 1 | # MVC Simples em PHP com banco de dados 2 | 3 | O mais simples possível, com apenas um controller e um model. 4 | 5 | ## Arquivos 6 | 7 | index.php 8 | Controller.php 9 | Model.php 10 | views/index.php 11 | db.sql 12 | 13 | ## Fluxo das informações 14 | 15 | Quando o index.php é chamado: 16 | 17 | - inclui o Controller.php 18 | - Instancia o Controller 19 | - Chama seu método index() 20 | 21 | Então o Controller é chamado: 22 | 23 | - Ele inclui o Model 24 | - Instancia o model 25 | - Chama seu método index(), que retorna o array $clients e armazena na variável $list; 26 | - Então o Controller inclui o index.php da view. 27 | 28 | Quando o Model é chamado 29 | 30 | - Ele define um array multi dimensional na variável $clients e insere 4 clientes, com código, nome e idade 31 | - Retorna em seu método index() este array 32 | - Este array é recebido pelo Controller 33 | 34 | Quando o index.php é chamado 35 | 36 | - Mostra algum texto explicativo na tela 37 | - Cria uma tabela HTML 38 | - Joga na tabela o resultado de um for trazendo o array $list, vindo do Controller, que recebeu do Model 39 | 40 | No caso a View recebe do Controller e não diretamente do Model, o que é uma boa prática. 41 | 42 | 43 | -------------------------------------------------------------------------------- /mvc2/connection.php: -------------------------------------------------------------------------------- 1 | getMessage() . "
"; 8 | die(); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /mvc2/db.sql: -------------------------------------------------------------------------------- 1 | create table clients( 2 | id int primary key auto_increment, 3 | nome varchar(50), 4 | idade int 5 | ); 6 | 7 | insert into clients(nome, idade) values ('Pedro', 48), 8 | ('Jorge', 26), 9 | ('Marta', 35), 10 | ('João', 21); 11 | -------------------------------------------------------------------------------- /mvc2/index.php: -------------------------------------------------------------------------------- 1 | index(); 8 | 9 | 10 | -------------------------------------------------------------------------------- /mvc3/index.php: -------------------------------------------------------------------------------- 1 | Desculpe, perdi o código deste. Use o 4'; 3 | ?> 4 | MVC 4 5 | -------------------------------------------------------------------------------- /mvc4/App/Controllers/ClientController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once 'App/views/clients/index.php'; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mvc4/App/Controllers/ProductController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once 'App/views/products/index.php'; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mvc4/App/Models/Client.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM clients order by id"); 12 | $executa = $stmte->execute(); 13 | $clients = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 14 | 15 | return $clients; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mvc4/App/Models/Product.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM products order by id"); 12 | $executa = $stmte->execute(); 13 | $products = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 14 | 15 | return $products; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mvc4/App/views/clients/index.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |

MVC Simples em PHP - 4

4 |

Com banco de dados

5 | 6 |

Lista de clientes

7 |
8 | 9 | 26 |
10 | 11 | $value) { 18 | echo ''.$key . " - " . $value . "
"; 19 | } 20 | echo "
"; 21 | } 22 | 23 | ?> 24 |
25 |
27 | -------------------------------------------------------------------------------- /mvc4/App/views/products/index.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |

MVC Simples em PHP

4 |

Com banco de dados

5 | 6 |

Lista de produtos

7 |
8 |
9 | 27 |
10 | 11 | 12 | $value) { 19 | echo ''.$key . " - " . $value . "
"; 20 | } 21 | echo "
"; 22 | } 23 | 24 | ?> 25 |
26 |
28 | 29 | -------------------------------------------------------------------------------- /mvc4/Core/Model.php: -------------------------------------------------------------------------------- 1 | pdo = new \PDO("mysql:host=localhost;dbname=testes", 'root', 'root'); 14 | 15 | return $this->pdo; 16 | 17 | } catch (\PDOException $e) { 18 | print "Error!: " . $e->getMessage() . "
"; 19 | die(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mvc4/Core/README.md: -------------------------------------------------------------------------------- 1 | # Core 2 | 3 | Esta pasta abriga as classes básicas, ou seja, as classes pais. 4 | 5 | As classes da pasta App são filhas destas daqui e as extendem. 6 | 7 | Em App poderemos ter várias classes filhas de Model: ClientModel, ProductModel, etc. 8 | 9 | 10 | -------------------------------------------------------------------------------- /mvc4/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ribafs/mvc4", 3 | "description": "MINI MVC - um aplicativo simples, usando MVC de forma didática", 4 | "type": "project", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Ribamar FS", 9 | "email": "ribafs@gmail.com" 10 | } 11 | ], 12 | "minimum-stability": "dev", 13 | "require": {}, 14 | "autoload": 15 | { 16 | "psr-4": 17 | { 18 | "App\\" : "App/", 19 | "Core\\" : "Core/" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mvc4/db.sql: -------------------------------------------------------------------------------- 1 | create table clients( 2 | id int primary key auto_increment, 3 | nome varchar(50), 4 | idade int 5 | ); 6 | 7 | insert into clients(nome, idade) values ('Pedro', 48), 8 | ('Jorge', 26), 9 | ('Marta', 35), 10 | ('João', 21); 11 | 12 | create table products( 13 | id int primary key auto_increment, 14 | nome varchar(50), 15 | preco decimal(6,2) 16 | ); 17 | 18 | insert into products(nome, preco) values ('Banana', 2), 19 | ('Manga', 3), 20 | ('Laranja', 1.5), 21 | ('Groselha', 5); 22 | -------------------------------------------------------------------------------- /mvc4/index.php: -------------------------------------------------------------------------------- 1 |
2 |

Selecione

3 |
4 | Clientes    5 | Produtos 6 |
7 | index(); 16 | }elseif($acesso == 'products'){ 17 | $controllerPro = new \App\Controllers\ProductController(); 18 | $products = $controllerPro->index(); 19 | } 20 | } 21 | ?> 22 | -------------------------------------------------------------------------------- /mvc4/vendor/autoload.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/composer/InstalledVersions.php', 10 | ); 11 | -------------------------------------------------------------------------------- /mvc4/vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/Core'), 10 | 'App\\' => array($baseDir . '/App'), 11 | ); 12 | -------------------------------------------------------------------------------- /mvc4/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Core\\' => 5, 13 | ), 14 | 'A' => 15 | array ( 16 | 'App\\' => 4, 17 | ), 18 | ); 19 | 20 | public static $prefixDirsPsr4 = array ( 21 | 'Core\\' => 22 | array ( 23 | 0 => __DIR__ . '/../..' . '/Core', 24 | ), 25 | 'App\\' => 26 | array ( 27 | 0 => __DIR__ . '/../..' . '/App', 28 | ), 29 | ); 30 | 31 | public static $classMap = array ( 32 | 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 33 | ); 34 | 35 | public static function getInitializer(ClassLoader $loader) 36 | { 37 | return \Closure::bind(function () use ($loader) { 38 | $loader->prefixLengthsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixLengthsPsr4; 39 | $loader->prefixDirsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixDirsPsr4; 40 | $loader->classMap = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$classMap; 41 | 42 | }, null, ClassLoader::class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mvc5/.htaccess: -------------------------------------------------------------------------------- 1 | # This file is - if you set up MINI correctly - not needed. 2 | # But, for fallback reasons (if you don't route your vhost to /public), it will stay here. 3 | RewriteEngine on 4 | RewriteRule ^(.*) public/$1 [L] 5 | -------------------------------------------------------------------------------- /mvc5/App/Controllers/ClientController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once APP . 'views/templates/header.php'; 14 | require_once APP . 'views/clients/index.php'; 15 | require_once APP . 'views/templates/footer.php'; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mvc5/App/Controllers/ProductController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once APP . 'views/templates/header.php'; 14 | require_once APP . 'views/products/index.php'; 15 | require_once APP . 'views/templates/footer.php'; 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mvc5/App/Models/Client.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM clients order by id"); 12 | $executa = $stmte->execute(); 13 | $clients = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 14 | 15 | return $clients; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mvc5/App/Models/Product.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM products order by id"); 12 | $executa = $stmte->execute(); 13 | $products = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 14 | 15 | return $products; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mvc5/App/views/clients/index.php: -------------------------------------------------------------------------------- 1 | 4 |
5 |

Você está na view: App/views/clients/index.php

6 | 7 |
8 |

Lista de clientes

9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
IdNomeIdade
28 |
29 |
30 | -------------------------------------------------------------------------------- /mvc5/App/views/error/index.php: -------------------------------------------------------------------------------- 1 |
2 |

Esta é a página de erros. Verifique que seu controller ou method não existem.

3 |
4 | -------------------------------------------------------------------------------- /mvc5/App/views/products/index.php: -------------------------------------------------------------------------------- 1 | 4 |
5 |

Você está na view: App/views/product/index.php

6 | 7 |
8 |

Lista de produtos

9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
IdNomePreço
28 |
29 |
30 | -------------------------------------------------------------------------------- /mvc5/App/views/templates/footer.php: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /mvc5/App/views/templates/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MVC 5 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

Mini MVC 5

14 | 15 | 16 | 17 | 22 | -------------------------------------------------------------------------------- /mvc5/Core/ErrorController.php: -------------------------------------------------------------------------------- 1 | pdo = new \PDO("mysql:host=localhost;dbname=testes", 'root', 'root'); 14 | 15 | return $this->pdo; 16 | 17 | } catch (\PDOException $e) { 18 | print "Error!: " . $e->getMessage() . "
"; 19 | die(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mvc5/Core/README.md: -------------------------------------------------------------------------------- 1 | # Core 2 | 3 | Esta pasta abriga as classes básicas, ou seja, as classes pais. 4 | 5 | As classes da pasta App são filhas destas daqui e as extendem. 6 | 7 | Em App poderemos ter várias classes filhas de Model: ClientModel, ProductModel, etc. 8 | 9 | 10 | -------------------------------------------------------------------------------- /mvc5/Core/Router.php: -------------------------------------------------------------------------------- 1 | Url(); 11 | 12 | // Quando não for setado o urlController abrirá o ClientController como o default 13 | if (!$this->urlController) { 14 | $page = new \App\Controllers\ClientController(); 15 | $page->index(); 16 | 17 | }elseif ($this->urlController == 'clients') { 18 | $page = new \App\Controllers\ClientController(); 19 | $page->index(); 20 | 21 | } elseif ($this->urlController == 'products') { 22 | $page = new \App\Controllers\ProductController(); 23 | $page->index(); 24 | } else { 25 | $page = new \Core\ErrorController(); 26 | $page->index(); 27 | } 28 | } 29 | 30 | private function Url() 31 | { 32 | // Suporta descer apenas um nível de diretório no servidor web 33 | // Testado em: /mvc5 e em /testes/mvc5. Caso precise descer mais precisa ajustar o código abaixo 34 | $url = $_SERVER['REQUEST_URI']; 35 | $url = explode('/', $url);// Captura a URL 36 | $count = count($url); 37 | if($count == 4){ 38 | $url = $url[3]; 39 | }elseif($count == 3){ 40 | $url = $url[2]; 41 | } 42 | $this->urlController = $url; 43 | return $this->urlController; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mvc5/Core/config.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/composer/InstalledVersions.php', 10 | ); 11 | -------------------------------------------------------------------------------- /mvc5/vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/Core'), 10 | 'App\\' => array($baseDir . '/App'), 11 | ); 12 | -------------------------------------------------------------------------------- /mvc5/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Core\\' => 5, 13 | ), 14 | 'A' => 15 | array ( 16 | 'App\\' => 4, 17 | ), 18 | ); 19 | 20 | public static $prefixDirsPsr4 = array ( 21 | 'Core\\' => 22 | array ( 23 | 0 => __DIR__ . '/../..' . '/Core', 24 | ), 25 | 'App\\' => 26 | array ( 27 | 0 => __DIR__ . '/../..' . '/App', 28 | ), 29 | ); 30 | 31 | public static $classMap = array ( 32 | 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 33 | ); 34 | 35 | public static function getInitializer(ClassLoader $loader) 36 | { 37 | return \Closure::bind(function () use ($loader) { 38 | $loader->prefixLengthsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixLengthsPsr4; 39 | $loader->prefixDirsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixDirsPsr4; 40 | $loader->classMap = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$classMap; 41 | 42 | }, null, ClassLoader::class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mvc6/.htaccess: -------------------------------------------------------------------------------- 1 | # This file is - if you set up MINI correctly - not needed. 2 | # But, for fallback reasons (if you don't route your vhost to /public), it will stay here. 3 | RewriteEngine on 4 | RewriteRule ^(.*) public/$1 [L] 5 | -------------------------------------------------------------------------------- /mvc6/App/Controllers/ClientController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once APP . 'views/templates/header.php'; 14 | require_once APP . 'views/clients/index.php'; 15 | require_once APP . 'views/templates/footer.php'; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mvc6/App/Controllers/ProductController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once APP . 'views/templates/header.php'; 14 | require_once APP . 'views/products/index.php'; 15 | require_once APP . 'views/templates/footer.php'; 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mvc6/App/Models/Client.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM clients order by id"); 12 | $executa = $stmte->execute(); 13 | $clients = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 14 | 15 | return $clients; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mvc6/App/Models/Product.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM products order by id"); 12 | $executa = $stmte->execute(); 13 | $products = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 14 | 15 | return $products; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mvc6/App/views/clients/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | Você está na view: App/views/clients/index.php 4 |

5 | 6 |

Lista de clientes

7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
IdNomeIdade
26 |
27 |
28 | -------------------------------------------------------------------------------- /mvc6/App/views/error/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

Esta é a página de erros. Verifique que seu controller ou method não existem.

5 |
6 | -------------------------------------------------------------------------------- /mvc6/App/views/products/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | Você está na view: App/views/products/index.php 4 |

5 | 6 |

Lista de produtos

7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
IdNomePreço
27 |
28 | -------------------------------------------------------------------------------- /mvc6/App/views/templates/footer.php: -------------------------------------------------------------------------------- 1 |

2 |
3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mvc6/App/views/templates/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MVC 6 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

Mini MVC 6

15 |

Com autoload, PSR-4 e rotas simples

16 | 17 | 18 |
19 | Início 20 | Clientes 21 | Produtos 22 |
23 | 24 | -------------------------------------------------------------------------------- /mvc6/Core/ErrorController.php: -------------------------------------------------------------------------------- 1 | pdo = new \PDO("mysql:host=localhost;dbname=testes", 'root', 'root'); 14 | 15 | return $this->pdo; 16 | 17 | } catch (\PDOException $e) { 18 | print "Error!: " . $e->getMessage() . "
"; 19 | die(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /mvc6/Core/README.md: -------------------------------------------------------------------------------- 1 | # Core 2 | 3 | Esta pasta abriga as classes básicas, ou seja, as classes pais. 4 | 5 | As classes da pasta App são filhas destas daqui e as extendem. 6 | 7 | Em App poderemos ter várias classes filhas de Model: ClientModel, ProductModel, etc. 8 | 9 | 10 | -------------------------------------------------------------------------------- /mvc6/Core/config.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/composer/InstalledVersions.php', 10 | ); 11 | -------------------------------------------------------------------------------- /mvc6/vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/Core'), 10 | 'App\\' => array($baseDir . '/App'), 11 | ); 12 | -------------------------------------------------------------------------------- /mvc6/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Core\\' => 5, 13 | ), 14 | 'A' => 15 | array ( 16 | 'App\\' => 4, 17 | ), 18 | ); 19 | 20 | public static $prefixDirsPsr4 = array ( 21 | 'Core\\' => 22 | array ( 23 | 0 => __DIR__ . '/../..' . '/Core', 24 | ), 25 | 'App\\' => 26 | array ( 27 | 0 => __DIR__ . '/../..' . '/App', 28 | ), 29 | ); 30 | 31 | public static $classMap = array ( 32 | 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 33 | ); 34 | 35 | public static function getInitializer(ClassLoader $loader) 36 | { 37 | return \Closure::bind(function () use ($loader) { 38 | $loader->prefixLengthsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixLengthsPsr4; 39 | $loader->prefixDirsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixDirsPsr4; 40 | $loader->classMap = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$classMap; 41 | 42 | }, null, ClassLoader::class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mvc7/.htaccess: -------------------------------------------------------------------------------- 1 | # This file is - if you set up MINI correctly - not needed. 2 | # But, for fallback reasons (if you don't route your vhost to /public), it will stay here. 3 | RewriteEngine on 4 | RewriteRule ^(.*) public/$1 [L] 5 | -------------------------------------------------------------------------------- /mvc7/App/Controllers/ProductController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once APP . 'views/templates/header.php'; 14 | require_once APP . 'views/products/index.php'; 15 | require_once APP . 'views/templates/footer.php'; 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mvc7/App/Models/Client.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM clients order by id desc"); 10 | $executa = $stmte->execute(); 11 | $clients = $stmte->fetchall(); 12 | 13 | return $clients; 14 | } 15 | 16 | public function add($nome, $idade) 17 | { 18 | $sql = "INSERT INTO clients (nome, idade) VALUES (:nome, :idade)"; 19 | $query = $this->pdo->prepare($sql); 20 | $parameters = array(':nome' => $nome, ':idade' => $idade); 21 | $query->execute($parameters); 22 | } 23 | 24 | public function delete($id) 25 | { 26 | $sql = "DELETE FROM clients WHERE id = :id"; 27 | $query = $this->pdo->prepare($sql); 28 | $parameters = array(':id' => $id); 29 | $query->execute($parameters); 30 | } 31 | 32 | public function edit($id) 33 | { 34 | $sql = "SELECT id, nome, idade FROM clients WHERE id = :id LIMIT 1"; 35 | $query = $this->pdo->prepare($sql); 36 | $parameters = array(':id' => $id); 37 | $query->execute($parameters); 38 | return ($query->rowCount() ? $query->fetch() : false); 39 | } 40 | 41 | public function update($nome, $idade, $id) 42 | { 43 | $sql = "UPDATE clients SET nome = :nome, idade = :idade WHERE id = :id"; 44 | $query = $this->pdo->prepare($sql); 45 | $parameters = array(':nome' => $nome, ':idade' => $idade, ':id' => $id); 46 | 47 | $query->execute($parameters); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /mvc7/App/Models/Product.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM products order by id"); 12 | $executa = $stmte->execute(); 13 | $products = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 14 | 15 | return $products; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mvc7/App/views/clients/edit.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | Você está na view: App/views/clients/index.php 4 |

5 |

Editar clientes

6 |
7 |
8 |
9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |
19 |
20 |
21 |
22 |
23 | -------------------------------------------------------------------------------- /mvc7/App/views/error/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

Esta é a página de erros. Verifique que seu controller ou method não existem.

5 |
6 | -------------------------------------------------------------------------------- /mvc7/App/views/products/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | Você está na view: App/views/products/index.php 4 |

5 | 6 |

Lista de produtos

7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
IdNomePreço
27 |
28 | -------------------------------------------------------------------------------- /mvc7/App/views/templates/footer.php: -------------------------------------------------------------------------------- 1 |

2 |
3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mvc7/App/views/templates/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MVC 7 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

Mini MVC 7

15 |

(Com autoload, PSR-4 e rotas simples)

16 |
17 |
18 | Clientes 19 | Produtos 20 |
21 | 22 | -------------------------------------------------------------------------------- /mvc7/Core/ErrorController.php: -------------------------------------------------------------------------------- 1 | id) e mostre mais detalhes nas mensagens de erro 14 | // A barra antes do PDO (\PDO) é para indicar que estamos usando ele em seu próprio namespace e não é uma classe do nosso namespace 15 | $options = array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING); 16 | $this->pdo = new \PDO("mysql:host=localhost;dbname=testes", 'root', 'root', $options ); 17 | 18 | return $this->pdo; 19 | 20 | } catch (\PDOException $e) { 21 | print "Error!: " . $e->getMessage() . "
"; 22 | die(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /mvc7/Core/README.md: -------------------------------------------------------------------------------- 1 | # Core 2 | 3 | Esta pasta abriga as classes básicas, ou seja, as classes pais. 4 | 5 | As classes da pasta App são filhas destas daqui e as extendem. 6 | 7 | Em App poderemos ter várias classes filhas de Model: ClientModel, ProductModel, etc. 8 | 9 | 10 | -------------------------------------------------------------------------------- /mvc7/Core/config.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/composer/InstalledVersions.php', 10 | ); 11 | -------------------------------------------------------------------------------- /mvc7/vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/Core'), 10 | 'App\\' => array($baseDir . '/App'), 11 | ); 12 | -------------------------------------------------------------------------------- /mvc7/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Core\\' => 5, 13 | ), 14 | 'A' => 15 | array ( 16 | 'App\\' => 4, 17 | ), 18 | ); 19 | 20 | public static $prefixDirsPsr4 = array ( 21 | 'Core\\' => 22 | array ( 23 | 0 => __DIR__ . '/../..' . '/Core', 24 | ), 25 | 'App\\' => 26 | array ( 27 | 0 => __DIR__ . '/../..' . '/App', 28 | ), 29 | ); 30 | 31 | public static $classMap = array ( 32 | 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 33 | ); 34 | 35 | public static function getInitializer(ClassLoader $loader) 36 | { 37 | return \Closure::bind(function () use ($loader) { 38 | $loader->prefixLengthsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixLengthsPsr4; 39 | $loader->prefixDirsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixDirsPsr4; 40 | $loader->classMap = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$classMap; 41 | 42 | }, null, ClassLoader::class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mvc8/.htaccess: -------------------------------------------------------------------------------- 1 | # This file is - if you set up MINI correctly - not needed. 2 | # But, for fallback reasons (if you don't route your vhost to /public), it will stay here. 3 | RewriteEngine on 4 | RewriteRule ^(.*) public/$1 [L] 5 | -------------------------------------------------------------------------------- /mvc8/App/Controllers/ProductController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once APP . 'views/templates/header.php'; 14 | require_once APP . 'views/products/index.php'; 15 | require_once APP . 'views/templates/footer.php'; 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mvc8/App/Models/Client.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM clients order by id desc"); 10 | $executa = $stmte->execute(); 11 | $clients = $stmte->fetchall(); 12 | 13 | return $clients; 14 | } 15 | 16 | public function add($nome, $idade) 17 | { 18 | $sql = "INSERT INTO clients (nome, idade) VALUES (:nome, :idade)"; 19 | $query = $this->pdo->prepare($sql); 20 | $parameters = array(':nome' => $nome, ':idade' => $idade); 21 | $query->execute($parameters); 22 | } 23 | 24 | public function delete($id) 25 | { 26 | $sql = "DELETE FROM clients WHERE id = :id"; 27 | $query = $this->pdo->prepare($sql); 28 | $parameters = array(':id' => $id); 29 | $query->execute($parameters); 30 | } 31 | 32 | public function edit($id) 33 | { 34 | $sql = "SELECT id, nome, idade FROM clients WHERE id = :id LIMIT 1"; 35 | $query = $this->pdo->prepare($sql); 36 | $parameters = array(':id' => $id); 37 | $query->execute($parameters); 38 | return ($query->rowCount() ? $query->fetch() : false); 39 | } 40 | 41 | public function update($nome, $idade, $id) 42 | { 43 | $sql = "UPDATE clients SET nome = :nome, idade = :idade WHERE id = :id"; 44 | $query = $this->pdo->prepare($sql); 45 | $parameters = array(':nome' => $nome, ':idade' => $idade, ':id' => $id); 46 | 47 | $query->execute($parameters); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /mvc8/App/Models/Product.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM products order by id"); 12 | $executa = $stmte->execute(); 13 | $products = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 14 | 15 | return $products; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mvc8/App/views/clients/edit.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | Você está na view: App/views/clients/index.php 4 |

5 |

Editar clientes

6 |
7 |
8 |
9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 |
19 |
20 |
21 |
22 |
23 | -------------------------------------------------------------------------------- /mvc8/App/views/error/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

Esta é a página de erros. Verifique que seu controller ou method não existem.

5 |
6 | -------------------------------------------------------------------------------- /mvc8/App/views/products/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | Você está na view: App/views/products/index.php 4 |

5 | 6 |

Lista de produtos

7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
IdNomePreço
27 |
28 | -------------------------------------------------------------------------------- /mvc8/App/views/templates/footer.php: -------------------------------------------------------------------------------- 1 |

2 |
3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mvc8/App/views/templates/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MVC 8 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

Mini MVC 8

15 |

(Com autoload, PSR-4 e rotas simples)

16 |
17 |
18 | Clientes 19 | Produtos 20 |
21 | 22 | -------------------------------------------------------------------------------- /mvc8/Core/ErrorController.php: -------------------------------------------------------------------------------- 1 | host = HOST; 15 | $this->user = USER; 16 | $this->pass = PASS; 17 | $this->db = DB; 18 | $dsn = 'mysql:host='.$this->host.';dbname='.$this->db; 19 | 20 | try { 21 | // Para que usemos as variáveis como objeto ($client->id) e mostre mais detalhes nas mensagens de erro 22 | // A barra antes do PDO (\PDO) é para indicar que estamos usando ele em seu próprio namespace e não é uma classe do nosso namespace 23 | $options = array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING); 24 | $this->pdo = new \PDO($dsn, $this->user, $this->pass, $options ); 25 | 26 | return $this->pdo; 27 | 28 | } catch (\PDOException $e) { 29 | print "Error!: " . $e->getMessage() . "
"; 30 | die(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mvc8/Core/README.md: -------------------------------------------------------------------------------- 1 | # Core 2 | 3 | Esta pasta abriga as classes básicas, ou seja, as classes pais. 4 | 5 | As classes da pasta App são filhas destas daqui e as extendem. 6 | 7 | Em App poderemos ter várias classes filhas de Model: ClientModel, ProductModel, etc. 8 | 9 | 10 | -------------------------------------------------------------------------------- /mvc8/Core/config.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/composer/InstalledVersions.php', 10 | ); 11 | -------------------------------------------------------------------------------- /mvc8/vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/Core'), 10 | 'App\\' => array($baseDir . '/App'), 11 | ); 12 | -------------------------------------------------------------------------------- /mvc8/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Core\\' => 5, 13 | ), 14 | 'A' => 15 | array ( 16 | 'App\\' => 4, 17 | ), 18 | ); 19 | 20 | public static $prefixDirsPsr4 = array ( 21 | 'Core\\' => 22 | array ( 23 | 0 => __DIR__ . '/../..' . '/Core', 24 | ), 25 | 'App\\' => 26 | array ( 27 | 0 => __DIR__ . '/../..' . '/App', 28 | ), 29 | ); 30 | 31 | public static $classMap = array ( 32 | 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 33 | ); 34 | 35 | public static function getInitializer(ClassLoader $loader) 36 | { 37 | return \Closure::bind(function () use ($loader) { 38 | $loader->prefixLengthsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixLengthsPsr4; 39 | $loader->prefixDirsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixDirsPsr4; 40 | $loader->classMap = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$classMap; 41 | 42 | }, null, ClassLoader::class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mvc9/.htaccess: -------------------------------------------------------------------------------- 1 | # This file is - if you set up MINI correctly - not needed. 2 | # But, for fallback reasons (if you don't route your vhost to /public), it will stay here. 3 | RewriteEngine on 4 | RewriteRule ^(.*) public/$1 [L] 5 | -------------------------------------------------------------------------------- /mvc9/App/Controllers/ProductController.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | require_once APP . 'views/templates/header.php'; 14 | require_once APP . 'views/products/index.php'; 15 | require_once APP . 'views/templates/footer.php'; 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mvc9/App/Models/Client.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM clients order by id desc"); 10 | $executa = $stmte->execute(); 11 | $clients = $stmte->fetchall(); 12 | 13 | return $clients; 14 | } 15 | 16 | public function add($nome, $idade) 17 | { 18 | $sql = "INSERT INTO clients (nome, idade) VALUES (:nome, :idade)"; 19 | $query = $this->pdo->prepare($sql); 20 | $parameters = array(':nome' => $nome, ':idade' => $idade); 21 | $query->execute($parameters); 22 | } 23 | 24 | public function delete($id) 25 | { 26 | $sql = "DELETE FROM clients WHERE id = :id"; 27 | $query = $this->pdo->prepare($sql); 28 | $parameters = array(':id' => $id); 29 | $query->execute($parameters); 30 | } 31 | 32 | public function edit($id) 33 | { 34 | $sql = "SELECT id, nome, idade FROM clients WHERE id = :id LIMIT 1"; 35 | $query = $this->pdo->prepare($sql); 36 | $parameters = array(':id' => $id); 37 | $query->execute($parameters); 38 | return ($query->rowCount() ? $query->fetch() : false); 39 | } 40 | 41 | public function update($nome, $idade, $id) 42 | { 43 | $sql = "UPDATE clients SET nome = :nome, idade = :idade WHERE id = :id"; 44 | $query = $this->pdo->prepare($sql); 45 | $parameters = array(':nome' => $nome, ':idade' => $idade, ':id' => $id); 46 | 47 | $query->execute($parameters); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /mvc9/App/Models/Product.php: -------------------------------------------------------------------------------- 1 | pdo->query("SELECT * FROM products order by id"); 10 | $executa = $stmte->execute(); 11 | $products = $stmte->fetchall(\PDO::FETCH_ASSOC); // Para recuperar um Objeto utilize PDO::FETCH_OBJ 12 | 13 | return $products; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mvc9/App/views/error/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

Esta é a página de erros. Verifique que seu controller ou method não existem.

5 |
6 | -------------------------------------------------------------------------------- /mvc9/App/views/products/index.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | Você está na view: App/views/products/index.php 4 |

5 | 6 |

Lista de produtos

7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
IdNomePreço
27 |
28 | -------------------------------------------------------------------------------- /mvc9/App/views/templates/footer.php: -------------------------------------------------------------------------------- 1 |

2 |
3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /mvc9/App/views/templates/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MVC 9 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |

Mini MVC 9

16 |

(Com Autoload, PSR-4 e Rotas)

17 |
18 |
19 | Clientes    20 | Produtos 21 |
22 |
23 | -------------------------------------------------------------------------------- /mvc9/Core/ErrorController.php: -------------------------------------------------------------------------------- 1 | host = HOST; 15 | $this->user = USER; 16 | $this->pass = PASS; 17 | $this->db = DB; 18 | $dsn = 'mysql:host='.$this->host.';dbname='.$this->db; 19 | 20 | try { 21 | // Para que usemos as variáveis como objeto ($client->id) e mostre mais detalhes nas mensagens de erro 22 | // A barra antes do PDO (\PDO) é para indicar que estamos usando ele em seu próprio namespace e não é uma classe do nosso namespace 23 | $options = array(\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_OBJ, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING); 24 | $this->pdo = new \PDO($dsn, $this->user, $this->pass, $options ); 25 | 26 | return $this->pdo; 27 | 28 | } catch (\PDOException $e) { 29 | print "Error!: " . $e->getMessage() . "
"; 30 | die(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /mvc9/Core/README.md: -------------------------------------------------------------------------------- 1 | # Core 2 | 3 | Esta pasta abriga as classes básicas, ou seja, as classes pais. 4 | 5 | As classes da pasta App são filhas destas daqui e as extendem. 6 | 7 | Em App poderemos ter várias classes filhas de Model: ClientModel, ProductModel, etc. 8 | 9 | 10 | -------------------------------------------------------------------------------- /mvc9/Core/config.php: -------------------------------------------------------------------------------- 1 | $vendorDir . '/composer/InstalledVersions.php', 10 | ); 11 | -------------------------------------------------------------------------------- /mvc9/vendor/composer/autoload_namespaces.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/Core'), 10 | 'App\\' => array($baseDir . '/App'), 11 | ); 12 | -------------------------------------------------------------------------------- /mvc9/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Core\\' => 5, 13 | ), 14 | 'A' => 15 | array ( 16 | 'App\\' => 4, 17 | ), 18 | ); 19 | 20 | public static $prefixDirsPsr4 = array ( 21 | 'Core\\' => 22 | array ( 23 | 0 => __DIR__ . '/../..' . '/Core', 24 | ), 25 | 'App\\' => 26 | array ( 27 | 0 => __DIR__ . '/../..' . '/App', 28 | ), 29 | ); 30 | 31 | public static $classMap = array ( 32 | 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 33 | ); 34 | 35 | public static function getInitializer(ClassLoader $loader) 36 | { 37 | return \Closure::bind(function () use ($loader) { 38 | $loader->prefixLengthsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixLengthsPsr4; 39 | $loader->prefixDirsPsr4 = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$prefixDirsPsr4; 40 | $loader->classMap = ComposerStaticInit549afd4a90893584184c45fcc70215a6::$classMap; 41 | 42 | }, null, ClassLoader::class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /mvcx/Migrations/20200415153724_produtos.php: -------------------------------------------------------------------------------- 1 | table('produtos') 35 | ->addColumn('nome', 'string', ['null' => false]) 36 | ->addColumn('quantidade', 'integer') 37 | ->create(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /mvcx/Migrations/20200415153733_pedidos.php: -------------------------------------------------------------------------------- 1 | table('pedidos') 35 | ->addColumn('data', 'date') 36 | ->addColumn('quantidade', 'integer') 37 | ->addColumn('produto_id', 'integer', ['null' => true]) 38 | ->addForeignKey('produto_id', 'produtos', 'id', ['delete'=> 'SET_NULL', 'update'=> 'NO_ACTION']) 39 | ->create(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /mvcx/Migrations/MigrationsCake3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ribafs/simplest-mvc/a55488c1bfd13baf16f55971f409667584c3948b/mvcx/Migrations/MigrationsCake3.pdf -------------------------------------------------------------------------------- /mvcx/Migrations/seeds: -------------------------------------------------------------------------------- 1 | 2 | php vendor/bin/phinx seed:create UserSeeder 3 | 4 | 5 | phinx schema:dump 6 | vendor/bin/phinx schema:dump 7 | 8 | php vendor/bin/phinx seed:run -s UserSeeder 9 | 10 | Comoo gerar um arquivo .sql exportando do banco? 11 | Funciona no Cake3 12 | 13 | bin/cake bake seed --data tabela 14 | 15 | Dica: se estiver usando outro framework instalar o cake3 somemnte para exportar os registros via seed 16 | composer create-project --prefer-dist cakephp/app:3.* appteste 17 | 18 | Basta instalar e configurar o banco e executar: 19 | bin/cake bake seed --data tabela 20 | 21 | Ele gera o arquivo contendo todos os registros da tabela 22 | 23 | Para exportar apenas 10 registros: 24 | bin/cake bake seed --data --limit 10 tabela 25 | 26 | -------------------------------------------------------------------------------- /mvcx/pdox/.gitignore: -------------------------------------------------------------------------------- 1 | /.git 2 | /.DS_Store 3 | /composer.lock 4 | /vendor 5 | /index.php 6 | /.htaccess 7 | /.idea 8 | -------------------------------------------------------------------------------- /mvcx/pdox/.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - "7.0" 4 | - "5.6" 5 | - "5.5" 6 | - "5.4" -------------------------------------------------------------------------------- /mvcx/pdox/LICENCE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015, İzni Burak Demirtaş 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /mvcx/pdox/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "izniburak/pdox", 3 | "type": "library", 4 | "description": "Useful Query Builder, PDO Class for PHP. A simple access to your SQL records.", 5 | "keywords": ["php","pdo","sql","query","builder"], 6 | "homepage": "https://github.com/izniburak/PDOx", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "İzni Burak Demirtaş", 11 | "email": "info@burakdemirtas.org", 12 | "homepage": "http://burakdemirtas.org" 13 | } 14 | ], 15 | "require": { 16 | "php": ">=5.5.0", 17 | "ext-pdo": "*", 18 | "ext-json": "*" 19 | }, 20 | "autoload": { 21 | "psr-4": { 22 | "Buki\\": "src" 23 | } 24 | }, 25 | "minimum-stability": "dev" 26 | } 27 | -------------------------------------------------------------------------------- /mvcx/pdox/example.php: -------------------------------------------------------------------------------- 1 | 6 | * @ Web: http://burakdemirtas.org 7 | * @ URL: https://github.com/izniburak/PDOx 8 | * @ Licence: The MIT License (MIT) - Copyright (c) - http://opensource.org/licenses/MIT 9 | * 10 | */ 11 | 12 | require 'vendor/autoload.php'; 13 | 14 | // database config 15 | $config = [ 16 | 'host' => 'localhost', 17 | 'driver' => 'mysql', 18 | 'database' => 'test', 19 | 'username' => 'root', 20 | 'password' => '', 21 | 'charset' => 'utf8', 22 | 'collation' => 'utf8_general_ci', 23 | 'prefix' => '' 24 | ]; 25 | 26 | // start PDOx 27 | $db = new \Buki\Pdox($config); 28 | 29 | // Select Records 30 | $records = $db->table('pages') 31 | ->where('age', '>', 18) 32 | ->orderBy('id', 'desc') 33 | ->limit(10) 34 | ->getAll(); 35 | 36 | var_dump($records); 37 | -------------------------------------------------------------------------------- /mvcx/pdox/src/PdoxInterface.php: -------------------------------------------------------------------------------- 1 | 'localhost', 7 | 'driver' => 'mysql', 8 | 'database' => 'test', 9 | 'username' => 'root', 10 | 'password' => '', 11 | 'charset' => 'utf8', 12 | 'collation' => 'utf8_general_ci', 13 | 'prefix' => '' 14 | ]; 15 | 16 | $db = new \Buki\Pdox($config); 17 | 18 | 19 | $query = $db->table('pages')->where('year', 2014)->where('status', 0)->delete(); 20 | 21 | if($query) 22 | { 23 | echo 'Record(s) deleted!'; 24 | } -------------------------------------------------------------------------------- /mvcx/pdox/tests/InsertTest.php: -------------------------------------------------------------------------------- 1 | 'localhost', 7 | 'driver' => 'mysql', 8 | 'database' => 'test', 9 | 'username' => 'root', 10 | 'password' => '', 11 | 'charset' => 'utf8', 12 | 'collation' => 'utf8_general_ci', 13 | 'prefix' => '' 14 | ]; 15 | 16 | $db = new \Buki\Pdox($config); 17 | 18 | $data = [ 19 | 'name' => 'Burak', 20 | 'surname' => 'Demirtaş', 21 | 'age' => '24', 22 | 'country' => 'Turkey', 23 | 'city' => 'Ankara', 24 | 'status' => 1 25 | ]; 26 | 27 | $query = $db->table('users')->insert($data); 28 | 29 | if($query) 30 | { 31 | echo 'Record added!
' . 32 | 'InsertID: ' . $db->insertId(); 33 | } -------------------------------------------------------------------------------- /mvcx/pdox/tests/JoinTest.php: -------------------------------------------------------------------------------- 1 | 'localhost', 7 | 'driver' => 'mysql', 8 | 'database' => 'test', 9 | 'username' => 'root', 10 | 'password' => '', 11 | 'charset' => 'utf8', 12 | 'collation' => 'utf8_general_ci', 13 | 'prefix' => '' 14 | ]; 15 | 16 | $db = new \Buki\Pdox($config); 17 | 18 | $records = $db->table('authors') 19 | ->select('authors.name, articles.title, articles.slug') 20 | ->join('articles', 'users.id', 'articles.user_id') 21 | ->where('users.status', 1) 22 | ->where('articles.status', 1) 23 | ->orderBy('articles.created_at', 'desc') 24 | ->limit(10) 25 | ->getAll(); 26 | 27 | foreach($records as $record) 28 | { 29 | echo $record->name . '
' . 30 | $record->title . '
' . 31 | $record->slug; 32 | } -------------------------------------------------------------------------------- /mvcx/pdox/tests/SelectTest.php: -------------------------------------------------------------------------------- 1 | 'localhost', 7 | 'driver' => 'mysql', 8 | 'database' => 'test', 9 | 'username' => 'root', 10 | 'password' => '', 11 | 'charset' => 'utf8', 12 | 'collation' => 'utf8_general_ci', 13 | 'prefix' => '' 14 | ]; 15 | 16 | $db = new \Buki\Pdox($config); 17 | 18 | $records = $db->table('users') 19 | ->select('name, surname, age') 20 | ->where('age', '>', 18) 21 | ->orderBy('id', 'desc') 22 | ->limit(20) 23 | ->getAll(); 24 | 25 | foreach($records as $record) 26 | { 27 | echo $record->name . '
' . 28 | $record->surname . '
' . 29 | $record->age; 30 | } -------------------------------------------------------------------------------- /mvcx/pdox/tests/UpdateTest.php: -------------------------------------------------------------------------------- 1 | 'localhost', 7 | 'driver' => 'mysql', 8 | 'database' => 'test', 9 | 'username' => 'root', 10 | 'password' => '', 11 | 'charset' => 'utf8', 12 | 'collation' => 'utf8_general_ci', 13 | 'prefix' => '' 14 | ]; 15 | 16 | $db = new \Buki\Pdox($config); 17 | 18 | $data = [ 19 | 'username' => 'new-user-name', 20 | 'password' => md5('new-password'), 21 | 'status' => 1 22 | ]; 23 | 24 | $query = $db->table('users')->where('id', 17)->update($data); 25 | 26 | if($query) 27 | { 28 | echo 'Record updated!'; 29 | } -------------------------------------------------------------------------------- /mvcx/tracy-debug.md: -------------------------------------------------------------------------------- 1 | # Bibliteca de Debug para PHP 2 | 3 | Ajuda a detectar e corrigir error 4 | 5 | Mede tempo de execução de scripts/consultas 6 | 7 | Vê o consumo de memória 8 | 9 | composer require tracy/tracy 10 | 11 | 12 | index.php 13 | 14 | 15 | 16 | require 'vendor/autoload.php'; 17 | 18 | use Tracy\Debugger; 19 | 20 | Debugger::enable(); 21 | 22 | Debugger::$showBar = true; 23 | 24 | $os->teste(); 25 | 26 | Traz uma função dump($var) para ajudar no debug. 27 | 28 | Timer 29 | 30 | Debugger::timer(); 31 | 32 | // sweet dreams my cherrie 33 | sleep(2); 34 | 35 | $elapsed = Debugger::timer(); 36 | // $elapsed = 2 37 | 38 | ou 39 | Debugger::timer(); // runs the timer 40 | 41 | ... // some time-consuming operation 42 | 43 | echo Debugger::timer(); // elapsed time in seconds 44 | 45 | Obs 46 | 47 | Em produção é muito importante desabilitar tracy e toda exibição de erros 48 | 49 | Mais detalhes 50 | 51 | https://tracy.nette.org/en/guide 52 | 53 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/README.md: -------------------------------------------------------------------------------- 1 | # MVC Router inicial 2 | 3 | Esta série não é oriunda diretamente do mini-framework/mini3, mas usa parte da estrutura do mini3 e uma versão simplificada da classe Router do mini3. 4 | 5 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial/.htaccess: -------------------------------------------------------------------------------- 1 | # Este arquivo redireciona todas os requests para a pasta public/ e habilita o mod_rewrite 2 | RewriteEngine on 3 | RewriteRule ^(.*) public/$1 [L] 4 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial/README.md: -------------------------------------------------------------------------------- 1 | # MVC Router inicial 1 2 | 3 | Esta versão não usa banco. Usa um router bem simplificado e com várias limitações mas implementa namespace com PSR-4. 4 | Implementa o MVC na pasta src. 5 | 6 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ribafs/mvc-inicial", 3 | "description": "MVC inicial", 4 | "type": "project", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Ribamar FS", 9 | "email": "ribafs@gmail.com" 10 | } 11 | ], 12 | "minimum-stability": "stable", 13 | "require": { 14 | 15 | }, 16 | "autoload": 17 | { 18 | "psr-4": 19 | { 20 | "Mvc\\" : "src/" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial/namespace.txt: -------------------------------------------------------------------------------- 1 | Implementando namespace com PSR-4 em aplicativo PHP 2 | 3 | 1 - Criar a estrutura de diretórios 4 | 5 | 2 - Criar o composer.json com o autoload e psr-4 6 | 7 | 3 - Digitar o namespace em cada uma das classes do namespace e somente nas classes 8 | 9 | 4 - Adicionar ao index.php do raiz: 10 | 11 | require_once 'vendor/autoload.php'; 12 | 13 | Concluir o aplicativo usando o namespace 14 | 15 | Após concluir execute no raiz do aplicativo: 16 | 17 | composer dumpautoload 18 | 19 | Teste o aplicativo no navegador 20 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial/projeto.txt: -------------------------------------------------------------------------------- 1 | Tentar criar todo com o conhecimento adquirido até agora 2 | 3 | public/index.php 4 | src/bootstrap.php 5 | src/config.php 6 | src/Controller 7 | src/Router 8 | src/Model 9 | src/View 10 | src/templates 11 | 12 | Vou usar namespace com psr-4 que dá menos trabalho. 13 | 14 | O Controller é chamado inicialmente pelo bootstrap 15 | Então ele instancia o model e chama seu index e guarda em $model 16 | O controller instancia a view e passa $model para seu método index que é devolvido para bootstrap 17 | 18 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial/public/.htaccess: -------------------------------------------------------------------------------- 1 | # Necessário para evitar problemas ao usar um controlador chamado "index" e ter um root index.php 2 | # mais aqui: http://httpd.apache.org/docs/2.2/content-negotiation.html 3 | Options -MultiViews 4 | 5 | # Ativar a URL rewriting (como myproject.com/controller/action/1/2/3) 6 | RewriteEngine On 7 | 8 | # Prevenir pessoas de visualizar diretamente nos diretórios 9 | Options -Indexes 10 | 11 | # Se as seguintes condições forem verdadeiras, reescreva a URL: 12 | # Se o nome do arquivo solicitado não for um diretório, 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | 15 | #e se o nome do arquivo solicitado não for um arquivo comum existente, 16 | RewriteCond %{REQUEST_FILENAME} !-f 17 | 18 | # e se o requesitidado arquivo não for um link simmbólico, 19 | RewriteCond %{REQUEST_FILENAME} !-l 20 | 21 | # então reescreva a URL da seguinte maneira: 22 | # Pegue o nome do arquivo inteiro da solicitação e forneça-o como o valor de um 23 | # "url" parâmetro de consulta para index.php. Anexe qualquer string de consulta da 24 | # URL original como mais parâmetros de consulta (QSA) e pare 25 | # processando este arquivo .htaccess (L). 26 | RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 27 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial/public/index.php: -------------------------------------------------------------------------------- 1 | index(); 12 | 13 | $view = new ClientesView(); 14 | return $view->index($model); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial/src/Model/ClientesModel.php: -------------------------------------------------------------------------------- 1 | index(); 13 | 14 | //use Mini\Core\Router; 15 | //echo 'ok';exit; 16 | //$app = new Router(); 17 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial/src/config.php: -------------------------------------------------------------------------------- 1 | array($baseDir . '/src'), 10 | ); 11 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial/vendor/composer/autoload_static.php: -------------------------------------------------------------------------------- 1 | 11 | array ( 12 | 'Mvc\\' => 4, 13 | ), 14 | ); 15 | 16 | public static $prefixDirsPsr4 = array ( 17 | 'Mvc\\' => 18 | array ( 19 | 0 => __DIR__ . '/../..' . '/src', 20 | ), 21 | ); 22 | 23 | public static function getInitializer(ClassLoader $loader) 24 | { 25 | return \Closure::bind(function () use ($loader) { 26 | $loader->prefixLengthsPsr4 = ComposerStaticInit2c68dab80940272cf8f3a1c37a5f84f4::$prefixLengthsPsr4; 27 | $loader->prefixDirsPsr4 = ComposerStaticInit2c68dab80940272cf8f3a1c37a5f84f4::$prefixDirsPsr4; 28 | 29 | }, null, ClassLoader::class); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial2/.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.lock 3 | 4 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial2/.htaccess: -------------------------------------------------------------------------------- 1 | # Este arquivo redireciona todas os requests para a pasta public/ e habilita o mod_rewrite 2 | RewriteEngine on 3 | RewriteRule ^(.*) public/$1 [L] 4 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial2/README.md: -------------------------------------------------------------------------------- 1 | # MVC Router inicial 2 2 | 3 | Esta versão ainda não usa banco. Usa um router bem simplificado e com várias limitações. 4 | Implementa o namespace com PSR-4 e MVC na pasta src. 5 | 6 | 7 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial2/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ribafs/scaffold-mvc", 3 | "description": "SCAFFOLD PHP MVC", 4 | "type": "project", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Ribamar FS", 9 | "email": "ribafs@gmail.com" 10 | } 11 | ], 12 | "minimum-stability": "stable", 13 | "require": { 14 | 15 | }, 16 | "autoload": 17 | { 18 | "psr-4": 19 | { 20 | "Mvc\\" : "src/" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial2/public/.htaccess: -------------------------------------------------------------------------------- 1 | # Necessário para evitar problemas ao usar um controlador chamado "index" e ter um root index.php 2 | # mais aqui: http://httpd.apache.org/docs/2.2/content-negotiation.html 3 | Options -MultiViews 4 | 5 | # Ativar a URL rewriting (como myproject.com/controller/action/1/2/3) 6 | RewriteEngine On 7 | 8 | # Prevenir pessoas de visualizar diretamente nos diretórios 9 | Options -Indexes 10 | 11 | # Se as seguintes condições forem verdadeiras, reescreva a URL: 12 | # Se o nome do arquivo solicitado não for um diretório, 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | 15 | #e se o nome do arquivo solicitado não for um arquivo comum existente, 16 | RewriteCond %{REQUEST_FILENAME} !-f 17 | 18 | # e se o requesitidado arquivo não for um link simmbólico, 19 | RewriteCond %{REQUEST_FILENAME} !-l 20 | 21 | # então reescreva a URL da seguinte maneira: 22 | # Pegue o nome do arquivo inteiro da solicitação e forneça-o como o valor de um 23 | # "url" parâmetro de consulta para index.php. Anexe qualquer string de consulta da 24 | # URL original como mais parâmetros de consulta (QSA) e pare 25 | # processando este arquivo .htaccess (L). 26 | RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] 27 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial2/public/css/custom.css: -------------------------------------------------------------------------------- 1 | .navbar-dark .navbar-nav .nav-link { 2 | color: #a1e1ed; 3 | } 4 | .center-img { 5 | display: block; 6 | margin-left: auto; 7 | margin-right: auto; 8 | width: 20%; 9 | } 10 | 11 | .bg-gray{ 12 | background-color: #e8e3e3; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial2/public/index.php: -------------------------------------------------------------------------------- 1 | todosClientes(); 19 | 20 | // Carregar a view. Com as views nós podemoms mostrar $todos e a soma facilmente 21 | $view = new ClientesView(); 22 | $view->render($todos); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial2/src/Core/Model.php: -------------------------------------------------------------------------------- 1 | user_name ! 31 | // Por exemplo, fetch mode FETCH_ASSOC deve retornar resultados como este: $result["user_name] ! 32 | // @see http://www.php.net/manual/en/pdostatement.fetch.php 33 | $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING); 34 | 35 | // TODO - Criar uma classe singleton para o Model 36 | // Gerar uma conexão ao banco de dados, usando o conector PDO 37 | // @see http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/ 38 | $dsn = DB_TYPE . ':host=' . DB_HOST . ';port ='. DB_PORT . ';dbname=' . DB_NAME;// . $databaseEncodingenc; 39 | $this->pdo = new PDO($dsn , DB_USER, DB_PASS, $options); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial2/src/Model/ClientesModel.php: -------------------------------------------------------------------------------- 1 |

Index do clientes vindo da view. Recebendo do model: '.$todos.'

'; 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial2/src/bootstrap.php: -------------------------------------------------------------------------------- 1 | user_name ! 31 | // Por exemplo, fetch mode FETCH_ASSOC deve retornar resultados como este: $result["user_name] ! 32 | // @see http://www.php.net/manual/en/pdostatement.fetch.php 33 | $options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING); 34 | 35 | // TODO - Criar uma classe singleton para o Model 36 | // Gerar uma conexão ao banco de dados, usando o conector PDO 37 | // @see http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/ 38 | $dsn = DB_TYPE . ':host=' . DB_HOST . ';port ='. DB_PORT . ';dbname=' . DB_NAME;// . $databaseEncodingenc; 39 | $this->pdo = new PDO($dsn , DB_USER, DB_PASS, $options); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial3/src/View/ClientesView.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | MINI3 on GitHub.
4 | Caso tenha gostado do projeto mini3, suporte usando Rackspace como sua hospedagem [link afiliado]. 5 |
6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial3/src/templates/_includes/header.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <?=APP_TITTLE?> 6 | 7 | 8 | 9 | 10 | 11 |

12 |
13 | 14 | 21 |
22 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial3/src/templates/clientes/add.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Clientes

4 |
5 |
6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial3/src/templates/clientes/edit.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Clientes

4 |
5 |

6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 |
17 |
18 |
19 |


20 | -------------------------------------------------------------------------------- /rotas/mvc-router-inicial/mvc_router_inicial3/src/templates/error/index.php: -------------------------------------------------------------------------------- 1 |

2 |
3 |

Este controller e/ou action ( ) não existem.

4 |

Verifique o arquivo na pasta Controller ou a constante CONTROLLER_DEFAULT no config.php

5 |
6 | 7 |



8 | -------------------------------------------------------------------------------- /rotas/rota-simples/index.php: -------------------------------------------------------------------------------- 1 |