class PostController extends Controller
{
/**
* @param Request $request
* @Route("/post", name="post")
*/
public function newAction(Request $request)
{
// create a Post and give it some dummy data for this example
$task = new AdsList();
$task->setTitle('Write a blog post');
$task->setpostedAt(new \DateTime('tomorrow'));
$form = $this->createFormBuilder($task)
->add('title', TextType::class)
->add('desc',TextType::class)
->add('postedAt', DateType::class)
->add('save', SubmitType::class, array('label' => 'Create Post'))
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// $form->getData() holds the submitted values
$task = $form->getData();
// save the task to the database
$em = $this->getDoctrine()->getManager();
$em->persist($task);
$em->flush();
return $this->redirectToRoute('list');
}
return $this->render('postlist/post.html.twig', array(
'form' => $form->createView(),
));
}
}
j'ai ce contrôleur qui génère l'instruction SQL suivante lors de la soumission INSERT INTO ads_list (titre, desc, posted_at) VALUES (?,?,?) » Avec params [ "r3123r2" , "3er233r123r2", "2017-10-20"]Exception Uncaught PHP avec la date d'insertion Doctrine2
Cependant, MySQL dit non! :) quelque chose est mauvais (cette requête semble bon pour moi)
posted_at ressemble
/**
* @ORM\column(type="date", name="posted_at", options={"default": 0})
*/
protected $postedAt;
i l'erreur suivante
Uncaught PHP Exception Doctrine\DBAL\Exception\SyntaxErrorException: "An exception occurred while executing 'INSERT INTO ads_list (title, desc, posted_at) VALUES (?, ?, ?)' with params ["r3123r2", "3er233r123r2", "2017-10-20"]: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, posted_at) VALUES ('r3123r2', '3er233r123r2', '2017-10-20')' at line 1" at /vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 94
toute pensée?
Avez-vous défini 'database_name' dans votre fichier' parameters.yml'? –
oui je l'ai fait :) j'ai déjà un peu de travail SQL :) –
Si vous souhaitez utiliser le mot réservé, vous pouvez l'ajouter comme ceci '' l'entoure et il ne donnera aucune erreur. –