Just wondering if it is possible to only use some parts of the symfony form handling. For exampe, when creating CRUD actions via generate:doctrine:crud
I get something in my Controller (for handling create User POST requests) that looks like this:
$entity = new User();
$form = $this->createForm(new UserType(), $entity,
array(
'action' => $this->generateUrl('user_create'),
'method' => 'POST',
));
$form->handleRequest($request);
//Here I have a filled Entity
But what I want is to have this in a more reusable solution. Currently I have my business logic in a service called UserModel
. Here I also want to have the create
method to create, validate and persist a new entity. Tough the UserModel
should also be callable from some Command scripts via the console, so I probably won't always have Request
nor a Form
.
So now from the above code I know that Symfony is already somehow populating data to an Entity according to the UserType
definition, but how could I do that manually without having a Form
or a Request
and instead just some array of data?
So that I don't have to take care of setting the properties myself.
Edit:
The validation is no issue for populating the entity, I'm using the validator
later on the populated entity before persisting the data.
And also important for me would be that the passed related entity ids
will be handled/loaded automatically.