first commit

This commit is contained in:
2022-05-21 12:32:17 +02:00
parent 7043b0900e
commit 98e1f085c0
22 changed files with 3431 additions and 2 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\Entity1Repository;
class IndexController extends AbstractController
{
#[Route('/', name: 'app_index')]
public function index(Entity1Repository $repo): Response
{
$entity8 = $repo->findOneByName('entity 8');
return $this->render('index/index.html.twig', [
'controller_name' => 'IndexController',
'entity8' => $entity8
]);
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace App\DataFixtures;
use App\Entity\Entity1;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class AppFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
for ($i = 0; $i < 20; $i++) {
$e = new Entity1();
$e->setName('entity '.$i);
$manager->persist($e);
}
$manager->flush();
}
}
// symfony console doctrine:fixtures:load

0
src/Entity/.gitignore vendored Normal file
View File

35
src/Entity/Entity1.php Normal file
View File

@ -0,0 +1,35 @@
<?php
namespace App\Entity;
use App\Repository\Entity1Repository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: Entity1Repository::class)]
class Entity1
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
}

0
src/Repository/.gitignore vendored Normal file
View File

View File

@ -0,0 +1,66 @@
<?php
namespace App\Repository;
use App\Entity\Entity1;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Entity1>
*
* @method Entity1|null find($id, $lockMode = null, $lockVersion = null)
* @method Entity1|null findOneBy(array $criteria, array $orderBy = null)
* @method Entity1[] findAll()
* @method Entity1[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class Entity1Repository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Entity1::class);
}
public function add(Entity1 $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
public function remove(Entity1 $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);
if ($flush) {
$this->getEntityManager()->flush();
}
}
// /**
// * @return Entity1[] Returns an array of Entity1 objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('e')
// ->andWhere('e.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('e.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
public function findOneByName($value): ?Entity1
{
return $this->createQueryBuilder('e')
->andWhere('e.name = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
}