Created
April 20, 2016 02:07
-
-
Save arianmaykon/a0112ec6b81662cbba5206bc1bc6a275 to your computer and use it in GitHub Desktop.
Symfony - Base app + Crud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Gerar uma aplicação básica com Symfony Framework, um model/tabela e um módulo de CRUD para essa tabela (SEM NENHUMA LINHA DE CÓDIGO! - EM 10 PASSOS!!) | |
-------------------------------------------------------------------------------- | |
# 01 - Instala o Symfony Installer na máquina - From: http://symfony.com/doc/current/book/installation.html | |
sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony | |
sudo chmod a+x /usr/local/bin/symfony | |
-------------------------------------------------------------------------------- | |
# 02 - Cria o projeto base com Symfony (última versão disponível no instalador) | |
symfony new my_sf_app | |
-------------------------------------------------------------------------------- | |
# 03 - Acessa o diretório da aplicação criada e executa o comando do symfony para servir o app com o server embutido do PHP (5.4+) | |
cd my_sf_app | |
php bin/console server:run | |
-------------------------------------------------------------------------------- | |
# 04 - Exibe a aplicação base no browser (CTRL + C no terminal para/stop o servidor) | |
http://127.0.0.1:8000/ | |
-------------------------------------------------------------------------------- | |
# 05 - Cria o "nosso" Bundle | |
php bin/console generate:bundle | |
Preencher com: | |
Are you planning on sharing this bundle across multiple applications? [no]: no | |
Bundle name: MyCompanyBundle | |
Target Directory [src/]: | |
Configuration format (annotation, yml, xml, php) [annotation]: | |
-------------------------------------------------------------------------------- | |
# 06 - Cria o database no MySQL | |
php bin/console doctrine:database:create | |
-------------------------------------------------------------------------------- | |
# 07 - Cria a entidade Category | |
php bin/console doctrine:generate:entity | |
Preencher com: | |
The Entity shortcut name: MyCompanyBundle:Category | |
Configuration format (yml, xml, php, or annotation) [annotation]: | |
# 1º campo (o id já é criado por padrão) | |
New field name (press <return> to stop adding fields): name | |
Field type [string]: | |
Field length [255]: 150 | |
Is nullable [false]: | |
Unique [false]: true | |
# 2º campo | |
New field name (press <return> to stop adding fields): description | |
Field type [string]: | |
Field length [255]: | |
Is nullable [false]: true | |
Unique [false]: | |
# Enter para finalizar | |
-------------------------------------------------------------------------------- | |
# 08 - Cria as tabelas das entidades criadas no banco (força o update, se tiver altera, se n tiver criar, o ideal é usar migrations para gerenciar banco, alterações incrementais no banco conforme releases) | |
php bin/console doctrine:schema:update --force | |
-------------------------------------------------------------------------------- | |
# 09 - Gera um módulo CRUD baseado em uma entidade | |
php bin/console doctrine:generate:crud | |
Preencher com: | |
The Entity shortcut name: MyCompanyBundle:Category | |
Do you want to generate the "write" actions [no]? yes | |
Configuration format (yml, xml, php, or annotation) [annotation]: | |
Routes prefix [/category]: | |
Do you confirm generation [yes]? | |
-------------------------------------------------------------------------------- | |
# 10 - Rodamos novamente o servidor embutido para checar a rota criada | |
php bin/console server:run | |
-------------------------------------------------------------------------------- | |
# 11 - Acesse as rotas abaixo para testar o CRUD criado e as alterações feitas - Enjoy! | |
http://127.0.0.1:8000/ | |
http://127.0.0.1:8000/category/ | |
-------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment