Created
July 4, 2020 22:03
-
-
Save NandoKstroNet/845412b6edf8a2bdc82c3345f676f1e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |
use Symfony\Component\Routing\Annotation\Route; | |
use App\Entity\User; | |
use App\Entity\Address; | |
class DefaultController extends AbstractController | |
{ | |
/** | |
* @Route("/", name="default") | |
*/ | |
public function index() | |
{ | |
$name = 'Nanderson Castro'; | |
$manager = $this->getDoctrine()->getManager(); | |
$address = new Address(); | |
$address->setAddress('Rua Teste'); | |
$address->setNumber(100); | |
$address->setNeighborhood('Bairro'); | |
$address->setCity('São Luis'); | |
$address->setState('Maranhão'); | |
$address->setZipcode('65000-000'); | |
// $address->setUser($user); //setter para salvar o relacionamento | |
$user = new User(); | |
$user->setFirstName('Usuário'); | |
$user->setLastName('Teste'); | |
$user->setEmail('[email protected]'); | |
$user->setPassword('1232323232'); | |
$user->setCreatedAt(new \DateTime('now', new \DateTimeZone('America/Sao_Paulo'))); | |
$user->setUpdatedAt(new \DateTime('now', new \DateTimeZone('America/Sao_Paulo'))); | |
$user->setAddress($address); | |
$manager->persist($user); | |
$manager->flush(); | |
$user = $this->getDoctrine()->getRepository(User::class)->find(1); | |
return $this->render('index.html.twig', compact('name', 'user')); | |
} | |
/** | |
* @Route("/product/{slug}", name="product_single") | |
*/ | |
public function product($slug) | |
{ | |
return $this->render('single.html.twig', compact('slug')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment