This is my controller class
/**
* @Route("/category/management/new", name="category_new", methods={"GET","POST"})
* @param Request $request
* @return Response
* @throws Exception
*/
public function createCategory(Request $request): Response
{
$date= new DateTime();
$form =$this->createFormBuilder()
->add('name',TextType::class)
->add('tags',TextType::class,[
'required'=>false,
])
->add('parent', EntityType::class, [
'label'=> 'If this is a subcategory please select a parent',
'required'=>false,
'class' => Category::class,
'choice_label' => 'name',
])
->add('Create',SubmitType::class)
->getForm();
$form->handleRequest($request);
$user=$this->get('security.token_storage')->getToken()->getUser();
var_dump($date);
if($form->isSubmitted()){
$data = $form->getData();
$category = new Category();
$category->setName($data['name']);
$category->setTags($data['tags']);
$category->setParent($data['parent']);
$category->setCreatedAt(new DateTime());
$category->setCreatedBy($user);
$em = $this->getDoctrine()->getManager();
$em->persist($category);
$em->flush();
return $this->redirect($this->generateUrl('category_management'));
}
return $this->render('category_management/create.html.twig',[
'form' => $form->createView()
]);
i've tried running it without setCreatedAt(new Datetime()) and relying on the DB to do the work but it still errors out.
Tried making changes in the entity class and directly setting New Datetime in the setCreatedAt method
All these didnt work and im stuck