Archives for “Symfony”
// Symfony 2 public function updateAction($id) { $em = $this->getDoctrine()->getEntityManager(); $product = $em->getRepository('AcmeStoreBundle:Product')->find($id); if (!$product) { throw $this->createNotFoundException('No product found for id '.$id); } $product->setName('New product name!'); $em->flush(); return $this->redirect($this->generateUrl('homepage')); } # Django def updateAction(request, id): product = Product.objects.get(pk=id) # Product.DoesNotExist exception raised if not found product.name = u"New product name!" product.save() return HttpResponseRedirect(reverse('homepage'))
For all of you that don’t know what Less CSS is, check this first, but I will try to summarize it in a phrase: It is a way of writing cleaner CSS code using variables and mixins but with the need of being compiled to an actual CSS file. Lets see an example of .less [...]
We have been working for a while with the django framework and we were also early adopters of the symfony framework using it almost from the begining in 2005. So I think I can write some of my thoughts about these two frameworks and try to make some comparisons between them. I’m not gonna try [...]
I’m going to show a way that I’ve found to easily edit N1 relationships with the admin generator of symfony 1.2 Surely it can be polished, and maybe it could be done better another way, if you know how please let me know. We are going to use the next model schema: # config/schema.yml propel: [...]
dWhen executing this code: $this->items = $object->getItens(); ... foreach($this->items as $item) { ...yadda yadda $item->getId() yadda yadada } within a symfony action, the php engine throws: Notice: Indirect modification of overloaded property xxxActions::$items has no effect in xxxactions.class.php That’s related to a php bug , whose implications in symfony are described here. It looks like [...]
I was looking for some actions sharing methods weird solution (since I was trying to apply a per-action classes model, and I needed to use methods from one action onto another), and I had no luck at all. However, what I did find out was fabien saying repeteadly that actions code should not be messy, [...]
The concept around this is to serve a 1px image through a PHP script. This allows you to insert a new record or update an existing one about read mails. In your mail you only have to insert an image tag like this at the end of the template: <img src="<?php echo url_for('stats/image?bulletin='.$id, 'absolute=true') ?>" [...]
Generating a CSV file from an action to bring it to the users of one of our websites I encountered myself with the problem of Symfony’s MVC model and decorator pattern. Although I was using echo statements directly, Symfony was waiting for the action to finish to send headers and allow the download, so the [...]
Las cabeceras X-JSON salen de un modo misterioso en la documentacion de Prototype, e incluso en la de symfony. Pues bien, tiene utilidad, vienen muy bien para enviar datos desde la operacion ajax hecha en el servidor hasta la funcion javascript que se suele ejecutar en el status ‘complete’ Pero pasemos a un ejemplo:
Es posible combinar los dos métodos de validación del symfony, de modo que se pueda usar el fichero yml para las validaciones más comunes, y el método validateXXX() para alguna validación más especial Para el caso – por ejemplo – donde uno o varios de los campos de un formulario requira una validación compleja, mientras [...]
Cuando escribimos con el symfony un form_remote_tag(), si luego pretendemos, a traves de javascript, realizar acciones cuando el evento ‘submit’ del formulario ocurra, tendremos que andarmos con mucho ojo. Cuando en symfony escribimos: echo form_remote_tag(array( 'update'=>'formulario', 'url'=>'forms/microMasInfo', 'script'=>'true')); el symfony genera: <form onsubmit="new Ajax.Updater('formulario', '/forms/microMasInfo', { asynchronous:true, evalScripts:true, parameters:Form.serialize(this) }); return false;" action="/forms/microMasInfo" method="post"> Es [...]
Cuando el nombre de la tabla en la base de datos difiere del nombre en el modelo de objetos, necesitamos obtener el “phpName”. Una forma de hacer esto, útil cuando solamente tenemos un nombre de tabla y un ID, es: $tabla = Propel::getDatabaseMap()->getTable($miNombreDeTabla); $phpName = $tabla->getPhpName() ? $tabla->getPhpName() : sfInflector::camelize($tabla->getName()); return call_user_func(array($phpName.'Peer', 'retrieveByPK'), $miID); Por [...]
Recent Comments