Created
November 24, 2011 11:41
-
-
Save jblanche/1391164 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
# Avec Rails on écrirait : | |
def create | |
@product = Product.create({name => 'A Foo Bar', price => 19.99, description => 'Lorem ipsum dolor'}) | |
end | |
# ou plutôt (pour gérer les validations et redirections, non gérées dans l'exemple Symfony) | |
def create | |
@product = Product.new({name => 'A Foo Bar', price => 19.99, description => 'Lorem ipsum dolor'}) | |
if @product.save | |
redirect_to @product | |
else | |
render :action => "new" | |
end | |
end |
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
// src/Acme/StoreBundle/Controller/DefaultController.php | |
use Acme\StoreBundle\Entity\Product; | |
use Symfony\Component\HttpFoundation\Response; | |
// ... | |
public function createAction() | |
{ | |
$product = new Product(); | |
$product->setName('A Foo Bar'); | |
$product->setPrice('19.99'); | |
$product->setDescription('Lorem ipsum dolor'); | |
$em = $this->getDoctrine()->getEntityManager(); | |
$em->persist($product); | |
$em->flush(); | |
return new Response('Created product id '.$product->getId()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment