diff --git a/.idea/php.xml b/.idea/php.xml index 5daafc8e..38689f6e 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -91,6 +91,8 @@ + + diff --git a/.idea/sf4-test.iml b/.idea/sf4-test.iml index 251d1c96..9f7b3313 100644 --- a/.idea/sf4-test.iml +++ b/.idea/sf4-test.iml @@ -9,9 +9,11 @@ + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5fda3cf2..55dd6033 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,10 +2,15 @@ + + - - - + + + + + + + + + + + + + + + + + + + @@ -364,22 +368,23 @@ 1520949897852 - + - + - + @@ -534,14 +539,6 @@ - - - - - - - - @@ -598,34 +595,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -642,20 +611,34 @@ - + - - - - - + + + - + - - + + + + + + + + + + + + + + + + + + @@ -668,6 +651,16 @@ + + + + + + + + + + @@ -676,13 +669,39 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/composer.json b/composer.json index 3bef995e..8fd2d849 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "symfony/yaml": "^3.4" }, "require-dev": { + "doctrine/doctrine-fixtures-bundle": "^3.0", "symfony/browser-kit": "^3.4", "symfony/css-selector": "^3.4", "symfony/dotenv": "^3.4", diff --git a/composer.lock b/composer.lock index 032a387f..56cec5b2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "f622f00afd59c3a14e9d36ccff4cdc4e", + "content-hash": "ed6ed212a7401fdb77a64ea454462831", "packages": [ { "name": "doctrine/annotations", @@ -5232,6 +5232,126 @@ } ], "packages-dev": [ + { + "name": "doctrine/data-fixtures", + "version": "v1.2.2", + "source": { + "type": "git", + "url": "https://github.com/doctrine/data-fixtures.git", + "reference": "17fa5bfe6ff52e35cb3d9ec37c934a2f4bd1fa2e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/17fa5bfe6ff52e35cb3d9ec37c934a2f4bd1fa2e", + "reference": "17fa5bfe6ff52e35cb3d9ec37c934a2f4bd1fa2e", + "shasum": "" + }, + "require": { + "doctrine/common": "~2.2", + "php": "^5.6 || ^7.0" + }, + "conflict": { + "doctrine/orm": "< 2.4" + }, + "require-dev": { + "doctrine/dbal": "^2.5.4", + "doctrine/orm": "^2.5.4", + "phpunit/phpunit": "^5.4.6" + }, + "suggest": { + "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", + "doctrine/orm": "For loading ORM fixtures", + "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\DataFixtures": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Data Fixtures for all Doctrine Object Managers", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database" + ], + "time": "2016-09-20T10:07:57+00:00" + }, + { + "name": "doctrine/doctrine-fixtures-bundle", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineFixturesBundle.git", + "reference": "7fc29d2b18c61ed99826b21fbfd1ff9969cc2e7f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/7fc29d2b18c61ed99826b21fbfd1ff9969cc2e7f", + "reference": "7fc29d2b18c61ed99826b21fbfd1ff9969cc2e7f", + "shasum": "" + }, + "require": { + "doctrine/data-fixtures": "~1.0", + "doctrine/doctrine-bundle": "~1.0", + "php": ">=5.5.9|^7.0", + "symfony/doctrine-bridge": "~2.7|~3.0|~4.0", + "symfony/framework-bundle": "^3.3|^4.0" + }, + "require-dev": { + "symfony/phpunit-bridge": "^3.3" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Bundle\\FixturesBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Doctrine Project", + "homepage": "http://www.doctrine-project.org" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony DoctrineFixturesBundle", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "Fixture", + "persistence" + ], + "time": "2017-12-04T20:26:38+00:00" + }, { "name": "symfony/browser-kit", "version": "v3.4.6", diff --git a/config/bundles.php b/config/bundles.php index bd23f71c..c3f2ec2d 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -13,4 +13,5 @@ return [ Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true], Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], + Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], ]; diff --git a/src/Controller/ProductController.php b/src/Controller/ProductController.php index bbfb9967..8964a541 100644 --- a/src/Controller/ProductController.php +++ b/src/Controller/ProductController.php @@ -3,37 +3,32 @@ namespace App\Controller; use App\Entity\Product; +use App\Entity\ProductCategory; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class ProductController extends Controller { /** - * @Route("/product", name="product") + * @Route("/", name="product") */ public function index() { - $allProducts = $this->getDoctrine() - ->getRepository( Product::class ) - ->findAll(); + $allProducts = $this->getDoctrine() + ->getRepository( Product::class ) + ->findAll(); + $allCategories = $this->getDoctrine() + ->getRepository( ProductCategory::class ) + ->findAll(); // you can fetch the EntityManager via $this->getDoctrine() // or you can add an argument to your action: index(EntityManagerInterface $entityManager) - $entityManager = $this->getDoctrine()->getManager(); +// $entityManager = $this->getDoctrine()->getManager(); - $product = new Product(); - $product->setName( 'qzine n°spécial 1' ); - $product->setPrice( 19.99 ); - - // tell Doctrine you want to (eventually) save the Product (no queries yet) - $entityManager->persist( $product ); - - // actually executes the queries (i.e. the INSERT query) - $entityManager->flush(); // return new Response( 'Saved new product with id ' . $product->getId() ); return $this->render( 'product/index.html.twig', [ - 'product' => $product, + 'categories' => $allCategories, 'allProducts' => $allProducts, ] ); } diff --git a/src/DataFixtures/.gitignore b/src/DataFixtures/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/symfony.lock b/symfony.lock index 3104be04..cf9269b1 100644 --- a/symfony.lock +++ b/symfony.lock @@ -17,6 +17,9 @@ "doctrine/common": { "version": "v2.7.3" }, + "doctrine/data-fixtures": { + "version": "v1.2.2" + }, "doctrine/dbal": { "version": "v2.5.13" }, @@ -32,6 +35,15 @@ "doctrine/doctrine-cache-bundle": { "version": "1.3.2" }, + "doctrine/doctrine-fixtures-bundle": { + "version": "3.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "3.0", + "ref": "2ea6070ecf365f9a801ccaed4b31d4a3b7af5693" + } + }, "doctrine/doctrine-migrations-bundle": { "version": "1.2", "recipe": { diff --git a/templates/product/index.html.twig b/templates/product/index.html.twig index 02e03942..22c9edee 100644 --- a/templates/product/index.html.twig +++ b/templates/product/index.html.twig @@ -1,20 +1,46 @@ {% extends 'base.html.twig' %} -{% block title %}Hello {{ controller_name }}!{% endblock %} +{% block title %}Hello !{% endblock %} {% block body %} - + - This friendly message is coming from: -
    -
  • Your controller at src/Controller/ProductController.php
  • -
  • Your template at templates/product/index.html.twig
  • -
- +
+

Hello ! ✅

+
+ +

+ Catégories +

+ {% for c in categories %} +

{{ c.name }}

+ {% for p in c.products %} + + {% endfor %} + {% endfor %} + +
+ +
{% endblock %}