Created by
Created by
//Creating a project
symfony server:start
symfony server:stop
//Creating a controller
To create a databse first you need to modify .env with the root and the database name
DATABASE_URL="mysql://root@localhost/library5"
//Entity
//Creating & Updating Entity
in src/Repository*/
//Form
//Creating a form
//CRUD
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Request;
use App\Form\FORM_NAME;
use App\Entity\ENTITY_NAME;
use App\Repository\REPOSITORY_NAME;
Link: https://drive.google.com/file/d/1cYB47k98BxEydHVTlXbdjQUd3e7_lFCl/view
*/
//Creating
/*Parameters
$form=$this->createForm(AuthorFormType::class,$author);
$form->handleRequest($request);
if($form->isSubmitted()){
$em= $doctrine->getManager();
$em->persist($author);
$em->flush();
return $this->render('author/form.html.twig',[
'formA'=>$form->createView(),
]);
{{form_start(formA)}}
{{form_label(formA.email,"Your e-mail:")}}
{{form_widget(formA.email)}}
{{form_label(formA.Username,"Your Username:")}}
{{form_widget(formA.Username)}}
{{form_label(formA.age,"Your Age:")}}
{{form_widget(formA.age)}}
{{form_end(formA)}}
//---------------------------------------------//
/*Reading
Parameters
*/
$authors = $rep->findAll();
}
/*List path: templates/author/authorlist.html.twig
The list will use a For loop to list the authors plus showing the update & delete
NOTE: Use the path names and not the routes (author_delete/author_update)
An add button will also be added with the following line in case you wanted to insert
another author.
*/
{% block body %}
<table>
<thead>
<tr>
<th>Nom d utilisateur</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
//---------------------------------------------//
/*Updating
Parameters
*/
/* Updating needs an ID, putting the one you need to update in {id} will automatically
Create the form and fill it with the retrieved data, all you need to do is changing
whatever you want and pressing the update button*/
$author = $rep->find($id);
$form=$this->createForm(AuthorFormType::class,$author);
$form->handleRequest($request);
if($form->isSubmitted()){
$em= $doctrine->getManager();
$em->persist($author);
$em->flush();
return $this->render('author/form.html.twig',[
'formA'=>$form->createView(),
]);
*/
//---------------------------------------------//
/*Deleting
Parameters
$em= $doctrine->getManager();
$author= $rep->find($id);
$em->remove($author);
$em->flush();
/*The delete methode is the same as updating but without a form taking the {id}
$em->remove($author);
*/
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
->add('Type', ChoiceType::class, [
'choices' => [
],
])
/* NOTES TO TAKE:
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
->add('Add',SubmitType::class)
in order to show the "add" action button to make the form work
*/
/////////////////////////////////Part 2//////////////////////////////////////////
//Relationships:
/*OneToMany:
https://drive.google.com/file/d/1JhSEBWsOgg24VQ5arlAARszItXBky2VZ/view
*/
#[ORM\JoinColumn(nullable: true)]
//For this query we're getting the "Joueur List" Sorted by the "Nom"
$joueurs = $joueurRepository->findBy(array(),array('nom'=>'ASC'));
//SEARCH
return $this->createQueryBuilder('s')
->setParameter('parameter1', $parameter1)
->setParameter('parameter2',$parameter2)
->getQuery()
->getResult()
//Controller
//Twig
<form action="{{path('list_joueur')}}">
<input type="text" name="parameter1">
</form>
<table border=2>
<tr>
<td>Id</td>
<td>parameter1</td>
<td>parameter2</td>
</tr>
<tr>
<td>{{joueur.id}}</td>
<td>{{joueur.parameter1}}</td>
<td>{{joueur.parameter2}}</td>
</tr>
{% endfor %}
</table>