O documento apresenta os principais conceitos e estrutura para desenvolvimento de aplicações com o framework Zend Framework 2 (ZF2). É descrito o processo de instalação do ZF2 utilizando o Skeleton Application, com detalhamento da estrutura de pastas e arquivos. Também são apresentados tópicos como rotas, controllers, models, formulários e implementação de CRUD utilizando ZF2.
1. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Desenvolvendo
Aplicações com
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 1 / 34
2
2. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Er Galvão Abbott é Presidente da ABRAPHP – Associação
Brasileira de Profissionais PHP e Diretor da PHP Conference Brasil,
o principal evento de PHP da América Latina.
Trabalha há 20 anos desenvolvendo sistemas e aplicações
com interface web, sendo 15 destes com PHP e 7 com Zend
Framework. Trabalhou com diversas empresas de grande porte,
tanto nacionais como internacionais.
Palestra em eventos, ministra cursos presenciais e a distância
e é o fundador e líder do GU PHPBR, Grupo de Usuários de
abrangência nacional, que hoje conta com mais de 1.200
usuários cadastrados.
Site: http://www.galvao.eti.br/
Twitter: @galvao
Slides e Documentos: http://slideshare.net/ergalvao
https://speakerdeck.com/galvao
Github: http://github.com/galvao
Quem?!
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 2 / 34
3. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Objetivo
Apresentar detalhes Básicos → Intermediários sobre o
Zend Framework 2, detalhando conceitos envolvidos no
desenvolvimento de uma aplicação.
Serão apresentados os seguintes tópicos:
→ Porque escolher o ZF2?
→ Setup inicial, “Instalação” e Configuração
→ Ambientes
→ Rotas
→ Models, Controllers e Views
→ Validação
→ CRUD
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 3 / 34
4. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Por quê ZF2?
Open Source PHP >= 5.3
> 2 anos e meio namespaces
> 2.000 changesets closures
> 200 profissionais late static binding
Microsoft, Google, et al.
Composer Github
PHAR PHPUnit
100% OO TravisCI
S.O.L.I.D.
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 4 / 34
5. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Por quê ZF2?
Modular
modules.zendframework.com
Flexível
Dependency Injection,
application.config.php,
Module.php,
module.config.php
Eventos
Serviços
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 5 / 34
6. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Skeleton Application – Instalação
github.com/zendframework/ZendSkeletonApplication
Composer git clone git submodule download
composer create-project
-sdev
--repository-url="https://packages.zendframework.com"
zendframework/skeleton-application
path/to/install
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 6 / 34
7. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Skeleton Application – Estrutura
Configuração a nível de aplicação
Dados da aplicação
Módulos da aplicação
Raiz web
Componentes/Módulos externos
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 7 / 34
8. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Skeleton Application – Estrutura
Configuração “global” da Aplicação
Configuração do “ambiente”
Configuração a nível de aplicação
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 8 / 34
9. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Skeleton Application – Estrutura
Raiz do Módulo
Configuração do Módulo
i18n
Fonte do Módulo
Inicialização do Módulo
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 9 / 34
10. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Skeleton Application – Estrutura
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 10 / 34
11. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Skeleton Application – Estrutura
Zend Framework 2
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 11 / 34
12. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
MVC – ZF2 Style
Requisição
Inicialização
do Módulo Bootstrap
Roteamento Dispatch
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 12 / 34
Execução da
Aplicação
Resposta
13. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Setup inicial
public/index.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 13 / 34
14. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 14 / 34
Setup inicial
config/autoload/global.php
15. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 15 / 34
Setup inicial
config/autoload/local.php
16. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 16 / 34
Setup inicial
module/Application/Module.php
17. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Setup inicial
config/application.config.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 17 / 34
18. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
module/Application/config/module.config.php … ?!?!
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 18 / 34
19. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
module/Application/config/module.config.php … ?!?!
Muita calma nessa hora!
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 19 / 34
20. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Ufa!
module/Application/config/module.config.php
Rotas
Serviços
Controllers “disponíveis”
Questões sobre a camada de view
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 20 / 34
21. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Rotas
Literais
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 21 / 34
22. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Rotas
Com rotas filhas / com segmentos (≃ ZF1)
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 22 / 34
23. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Controllers
module/Application/src/Application/Controller/IndexController.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 23 / 34
24. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Dados Externos: Forms
module/Application/src/Application/Form/User/Register.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 24 / 34
25. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Dados Externos: Filtros
module/Application/src/Application/Filter/User/Register.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 25 / 34
26. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Models
module/Application/src/Application/Model/User.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 26 / 34
27. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Models
module/Application/src/Application/Model/UserTable.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 27 / 34
28. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Models
module/Application/src/Application/Module.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 28 / 34
29. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Models - CRUD
module/Application/src/Application/Model/UserTable.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 29 / 34
30. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Models - CRUD
module/Application/src/Application/Model/UserTable.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 30 / 34
31. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Models - CRUD
module/Application/src/Application/Model/UserTable.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 31 / 34
32. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Unindo as partes na Controller
module/Application/src/Application/Controller/UserController.php
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 32 / 34
33. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Concluindo...
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 33 / 34
34. Desenvolvendo Aplicações com ZF2 www.galvao.eti.br
Obrigado!
? Dúvidas?
↓ Críticas?
↑ Elogios?!
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 9/27/14 - 34 / 34