Skip to content

Instantly share code, notes, and snippets.

@eserdinyo
Last active November 8, 2018 14:02
Show Gist options
  • Save eserdinyo/82e60dae6afeb3d4545b976ffa943e52 to your computer and use it in GitHub Desktop.
Save eserdinyo/82e60dae6afeb3d4545b976ffa943e52 to your computer and use it in GitHub Desktop.
Veritabanı işlemleri with Symfony
<?php
// List games
/**
* @Route("/admin/oyunlar", name="oyunlar")
*/
public function index()
{
$games = $this ->.....->findAll();
return $this->render('admin/game/games.html.twig', [
'games' => $games,
]);
}
// Add to DB
/**
* @Route("/admin/oyunlar/add", name="add-game", methods="GET|POST")
*/
public function addGame(Request $request): Response
{
$game = new Games();
$form = ...;
//Save to DATABASE
if($form->isSubmitted() && $form->isValid()) {
$em = this...;
$em->persist($game);
$em->flush();
return $this->redirectToRoute('oyunlar');
}
}
// Delete from DB
/**
* @Route("/admin/oyunlar/delete/{id}", name="delete-game", methods="GET|POST")
*/
public function deleteGame(Games $games)
{
$em = this...;
$em->remove($games);
$em->flush();
return $this->redirectToRoute('oyunlar');
}
// Update Games
/**
* @Route("/admin/oyunlar/edit/{id}", name="edit-game", methods="GET|POST")
*/
public function editGame(Request $request, Games $games): Response
{
$form = ...;
//Save to DATABASE
if($form->isSubmitted() && $form->isValid()) {
$this ->getDoctrine() ->getManager()->flush();
return $this->redirectToRoute('oyunlar');
}
return $this->render('admin/game/edit-game.html.twig', [
'game'=>$games,
]);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment