Skip to content

Instantly share code, notes, and snippets.

View leopro's full-sized avatar

Leonardo Proietti leopro

  • Director of Software Engineering at MyTutor
  • @_leopro_
View GitHub Profile
<?php
if ($request->getMethod() == 'POST'){
$form->bindRequest($request);
if ($form->isValid()){
....
return $this->redirect($this->generateUrl('my_route'));
}
see https://gist.github.com/1223886
@leopro
leopro / ImageListener.php
Created June 21, 2012 13:51
Listener for image uploading
<?php
public function onFlush(OnFlushEventArgs $args)
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
foreach ($uow->getScheduledEntityInsertions() as $entity) {
if ($entity instanceof ImageInterface) {
@leopro
leopro / ArticoloAdmin.php
Created June 21, 2012 13:56
Sonata admin
<?php
protected function attachImages($object)
{
foreach ($object->getImages() as $image) {
$image->setArticolo($object);
}
}
public function prePersist($object)
<?php
class NewsAdmin extends BaseAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('Text', array('collapsed' => false))
->add('translations', 'collection', array('type' => new NewsI18nType()))
->end();
<?php
use Symfony\Component\HttpFoundation\Response;
public function showAction($id)
{
$repository = $this->getDoctrine()->getRepository('AcmeHelloBundle:Product');
$product = $repository->find($id);
if (!$product) {
throw $this->createNotFoundException('Nessun prodotto trovato per num id: '.$id);
public function indexAction($search)
{
if ( true === $search ) {
}
}
@leopro
leopro / app.php
Last active October 9, 2015 11:48
require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppCache($kernel);
@leopro
leopro / ControllerExtendableListener.php
Created September 4, 2012 14:58
Runtime controller extension
<?php
namespace Edimotive\SaloneBundle\Service;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Edimotive\SaloneBundle\Service\ControllerExtendableInterface;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Edimotive\SaloneBundle\Service\CustomControllerManager;
@leopro
leopro / Portal.php
Last active October 13, 2015 01:28
<?php
public function getRepository($name)
{
$em = $this->getEntityManager();
$entity = $this->getExtendedEntity($name);
if (is_null($entity)) {
$entity = $this->getDefaultEntity($name);
}