AlexandreDFM / Workshop_Introduction_Symfony

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Workshop-Introduction-Symfony

By Viltard Léo - Epitech Nice - 2023



Workshop Symfony
Introduction Framework Symfony

Epitech



Introduction

If you want to be present you need send an email to leo.viltard@epitech.eu with the following object:

[WSSymfony] Nom Prénom

/!\ Put your real firstname and lastname

In the mail share a .zip or .tar.gz file with the contents of your repository.\

Any work you do needs to be in the email, if you don't do this or didn't advance into the workshop at all you will be marked absent.



Installation

Symfony is a PHP Framework using to create website and web application. Built on top og the Symfony Components.

To start, we will install basic components to create our first web page.

  • PHP
  • Symfony
  • Composer
    • Composer is the main component of Symfony. It is usefully to set up the base of our project
  • Apache
    • Ubuntu:
      sudo apt install apache2
    
    • Fedora:
      sudo dnf install httpd-manual
    



Exercise 01: Create the skeleton

In this first part you will create your first Symfony skeleton website.

At least of exercise you need to have this following page:

To perform it, you have to use composer commands.



Exercise 02: Set up the controller

At least of this part you need to have functional controller and access to your homepage at the "/" path like follow:

To perform it, you have to learn how work the Symfony console.



Exercise 03: First steps with Twig & set up a form

As your controller suggests, we can find your template at:

templates/home/index.html.twig

Symfony use Twig as default templating engine.

Create a form under Symfony is easy.

Symfony abstracted the basic process and render your form fields dynamically from within PHP.

In this part you will create a function in the home controller to make your first builder instance.

When you FormBuilder instance perform, you can pass it to the template to create a view and rendering your form in Twig.

At least you should have the following page:



To go further: Doctrine entity

Now you have functional form.

__ Let's create our first Doctrine entity.__

Doctrine is an abstraction of the link between your PHP code and your database tables

To perform it, you have to pass through the Symfony console

  bin/console make:entity

You'll be asked a few questions:

Have a look in your files:

  src/Entity

There should new be Post entity file. Inside that file, you'll find all the fields you entered during the setup commented with ORM annotations.

Now we will use our new entity within our template:

Let me show you an example:

  use App/Entity/Post;
  ...
    $this->render('home/index.html',[
     'posts' => $this->getDoctrine()->getRepository(Post::class)
     ->findAll()
    ];
{% for post in posts %}
  <h1>{{ post.title }}</h1>
  <p>{{ post.description }}</p>
{% endfor %}

Is now up to you to know what to do with those code and how it works!

__ To finish, try to modify the form by adding Vue.js to the Framework!__

About


Languages

Language:PHP 38.9%Language:Twig 33.0%Language:Shell 28.1%