Skip to content

Instantly share code, notes, and snippets.

@norberttech
Forked from akondas/command.php
Last active August 29, 2015 14:23
Show Gist options
  • Save norberttech/4016ea5421d48fafe1fd to your computer and use it in GitHub Desktop.
Save norberttech/4016ea5421d48fafe1fd to your computer and use it in GitHub Desktop.
<?php
class ProductController
{
public function createProductAction(Request $request)
{
$command = new CreateProductCommand();
$form = $this->createForm(new ProductType(), $command);
$form->handle($request);
if ($form->isValid()) {
$this->get('command_bus')->handle($command);
$product = $this->get('product.repository')->getLastAddedProduct();
return new RedirectResponse(sprintf('/some/url/%s', (string) $product->getId()));
}
return ['form' => $form->createView()];
}
}
class CreateProductCommand
{
public $name;
public $priceAmout;
public $priceCurreny;
public $description;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment