zz - MiguelFieira/AMO-HANDBOEK GitHub Wiki

Symfony is a PHP framework for web applications and a set of reusable PHP components. Symfony is used by thousands of web applications (including BlaBlaCar.com and Spotify.com) and most of the popular PHP projects (including Drupal and Magento).

Handy Commands

This is a summary of the commands you can find on the other pages.

Startup Commands.

  1. To create your local project:
    composer create-project symfony/website-skeleton:4.3.* my-project

composer create-project symfony/website-skeleton:4.4.* my-project


  1. Laminas/laminas-code:
    composer require laminas/laminas-code

  1. To add your local dev server:
    composer require symfony/web-server-bundle --dev

  2. To start your local server use the command:
    php bin/console server:run

  3. Creating a Controller
    php bin/console make:controller

  4. Enter the name "DefaultController"

  5. You can change the default path of a router with annotation! * @Route("/", name="default")

  6. Database Setup
    Go your project and find the .env in the root map.
    DATABASE_URL=mysql://[email protected]:3306/croco

  7. Laminas/laminas-code:
    php bin/console doctrine:database:create

  8. Bootstrap Setup:
    The full code should look like this src/templates/base.html.twig

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>{% block title %}Welcome!{% endblock %}</title>
        {% block stylesheets %}{% endblock %}
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    </head>
    <body>
        {% block body %}{% endblock %}
        {% block javascripts %}{% endblock %}
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
    </body>
</html>
  1. To make a Entity use the command:
    php bin/console make:entity

  2. To force a Database update use the command:
    php bin/console doctrine:schema:update --force

  3. To make a Crud use the command:
    php bin/console make:crud

  4. Crud problem emtity:

 public function __toString()
    {
        return(string)$this->getId();
    }

List of basic commands you can use during your project.

  1. To create your Database use the command:
    php bin/console doctrine:database:create

  2. To clear your Cache use the command:
    php bin/console cache:clear

  3. To get a list of all your routes en paths:
    php bin/console debug:router


In the following example, i show you how to loop through a repository and pass along an array or 2 of data based on a property given in the DB.

Pay close attention to the render function i used, in the normal index there will be another property passed along to the index, add this here as well to avoid simple errors

public function index(StudentRepository $studentRepository) {

    $em = $this->getDoctrine()->getManager();
    $studenten = $studentRepository->findAll();

    $dranken =[];
    $eten = [];
    foreach($studenten as $student){
    switch($student->getSoort()){
        case hapje:
            $eten[] = $student->getId();
            break;
        case drankje:
            $dranken[] = $student->getId();
            break;
    }

    return $this->render('student/index.html.twig', [
            'dranken' => $dranken,
            'eten' => $eten,
        ]);
}

In case of the index function not belonging to the student entity, you can do the following: All you need to do is change the $studenten variable

$em = $this->getDoctrine()->getManager();
$studenten = $em->getRepository('App:Student')->findAll();

** Also, don't forget to change your cases to your own corresponding data in the DB **


data ophalen
Controler A en controler B. Data van controler A wordt opgehaald en in controler B getoond.
stap 1 - use App\Repository\ARepository; in controler B linken
stap 2 - data ophalen

public function index(ARepository $aRepository, BRepository $bRepository): Response
    {
        return $this->render('room/index.html.twig', [
            'as' => $aRepository->findAll(),
            'bs' => $bRepository->findAll(),
        ]);
    }

stap 3 - in tabel dat vertonnen

{% for a in as %}
{% for b in bs %}
tabel index
 <td>{{ a.imgSize }}</td>
 <td>{{ b.id }}</td>
{% endfor %}
{% endfor %}

    public function __toString() {
        return(string)$this->getNaam();
    }
$this->denyAccessUnlessGranted('ROLE_USER');
⚠️ **GitHub.com Fallback** ⚠️