05. Symfony project (4.1.1) - MuchChaca/KelKannes GitHub Wiki

1. Synfony project 4.1.1

1.1. Docs

1.2. New project

Use the following alias:

symfony-new app_name
# Then change directory
cd $_

1.3. Start the new project

Use the following alias:

heroku local up

1.4. Install annotations (if needed)

composer require annotations

composer require symfony/security-bundle

1.5. Symfony assets (if needed)

composer require symfony/asset

1.6. Install twig - Template engine (if needed)

composer require twig

1.7. Install forms (if needed)

composer require symfony/form

1.8. Install generator (if needed)

composer require symfony/maker-bundle --dev

1.9. Install ORM (if needed)

composer require orm

1.10. Install debug bar (if needed)

composer require symfony/profiler-pack

1.11. Create a controller

1.11.1. Symfony 3

1.11.2. Symfony 4+

bin/console make:controller ControllerName

If not working, check for dependencies

1.12. Create a new entity

bin/console make:entity

If not working, check for dependencies

1.13. ORM

doc

1.13.1. CRUD

https://symfony.com/blog/new-and-improved-generators-for-makerbundle

$ bin/console make:crud Entity

1.13.2. Migration

1.13.2.1. 😖 Doctrine migration (avoid)

$ bin/console make:migration
$ bin/console doctrine:migrations:migrate

1.13.2.2. ✔️ Heroku shortcut (better)

$ heroku local build

1.13.3. MEMO: Persisting

<?php
$em = $this->getDoctrine()->getManager();

$obj = new Obj();
$obj->setAttribute($attr);

$em->persist($obj);
$em->flush(); // commit
?>
bin/console doctrine:generate form <Entity>

1.13.4. Queries

<?php
$query = $em->createQuery('SELECT l from AppBundle:Livre l');
?>
<?php
$repository = $em->getRepository(<ENTITY>::class)
$all = $repository->findAll();
?>

1.14. Login system

Strongly inspired by: link

1.15. PHPDoc generator - Sami


1.16. Not obvious dependencies

So obvious that it is not

  • composer require symfony/orm-pack
  • composer require symfony/maker-bundle --dev
  • composer require symfony/asset
  • composer require symfony/maker-bundle --dev

Unit testing

Installation

$ composer require --dev symfony/phpunit-bridge

Helpful Symfony doc

🔗 link

Run test + coverage

bin/phpunit --coverage-text 

📝 Still under develoment

⚠️ **GitHub.com Fallback** ⚠️