<?php
// src/Controller/DefaultController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
class DefaultController extends BaseController
{
const ACCES_GLOBAL = 'ROLE_USER';
/**
* @Route("/", name="home")
*/
public function home(Request $request): Response
{
return $this->render('default/home.html.twig', $this->params);
}
/**
* @Route("/ping", name="ping")
*/
public function ping(Request $request): Response
{
return new Response(
'<html><body>Pong</body></html>'
);
}
/**
* @Route("/phpinfo", name="phpinfo")
*/
public function info(Request $request): Response
{
$this->params['page']['title'] = 'PHP INFO';
$this->params['page']['breadcrumbs'][] = [
'route' => 'phpinfo',
'label' => 'PHP Info',
];
ob_start();
phpinfo();
$this->params['page']['contents'] = ob_get_contents();
ob_end_clean();
return $this->render('default/common.html.twig', $this->params);
}
/**
* @Route("/contact", name="contact")
*/
public function contact(Request $request, ValidatorInterface $validator): Response
{
$this->params['page']['head']['title'] = 'Contact';
$this->params['page']['title'] = 'Contact';
$this->params['page']['breadcrumbs'][] = [
'route' => 'contact',
'label' => 'Contact',
];
$contact = new \App\Entity\Contact();
$form = $this->createForm('App\\Form\\ContactType', $contact);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//var_dump($article);
$errors = $validator->validate($contact);
//var_dump($errors);
if (count($errors) > 0) {
return new Response((string) $errors, 400);
}
//var_dump($form); var_dump($contact);
mail('mathieu@iprospective.fr', 'Nouveau message Alors', 'Objet: '.$contact->getSubject()."\r\n".'Message: '.$contact->getMessage());
}
$this->params['form'] = $form->createView();
return $this->render('default/contact.html.twig', $this->params);
}
}