-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathProjectController.php
More file actions
58 lines (47 loc) · 1.55 KB
/
ProjectController.php
File metadata and controls
58 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace App\Controller;
use App\Entity\Project;
use App\Type\ProjectType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
class ProjectController extends AbstractController
{
/**
*
* @Route("/projects/create", name="project_create")
* @param Request $request
* @return Response
*/
public function create(Request $request): Response
{
$project = new Project();
$form = $this->createForm(ProjectType::class, $project);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$project->setOwner($this->getUser());
$project->setGeneratedKey();
$this->getDoctrine()->getManager()->persist($project);
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('projects_show');
}
return $this->render("project/create.html.twig", [
'form' => $form->createView()
]);
}
/**
*
* @Route("/projects", name="projects_show")
* @return Response
*/
public function show(Request $request): Response
{
$projects = $this->getDoctrine()->getRepository(Project::class)
->findBy([]);
return $this->render("project/projectsList.html.twig", [
'projects' => $projects
]);
}
}