I want to create my entity Settings, which will have basic editable information about my page. I've created my entity <kbd>Settings.php</kbd> with this source:
<?php
namespace Acme\SettingsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
* @ORM\Table(name="settings")
*/
class Settings
{
/**
* @ORM\Column(type="string", length=100)
*/
protected $page_name;
/**
* @ORM\Column(type="string", length=100)
*/
protected $page_description;
/**
* @ORM\Column(type="string", length=100)
*/
protected $page_email;
}
and I do not know, how to tell in my controller that will be only overwriting existing data, not creating new. This is my controller <kbd>AdminController.php</kbd>
public function indexAction(Request $request)
{
if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException();
}
$settings = new Settings();
$form = $this->createForm('settings', $settings);
$form->handleRequest($request);
if($form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($settings);
try {
$em->flush();
} catch (\PDOException $e) {
// sth
}
$this->get('session')->getFlashBag()->add(
'success',
'Settings was successfuly changed'
);
}
return $this->render('AcmeSettingsBundle:Admin:index.html.twig', array('form' => $form));
}
I didn't test it, but I believe, it creates a new Settings object with new data. Any help?