Skip to content

Instantly share code, notes, and snippets.

@clubdesarrolladores
Created August 28, 2012 22:22
Show Gist options
  • Save clubdesarrolladores/3504870 to your computer and use it in GitHub Desktop.
Save clubdesarrolladores/3504870 to your computer and use it in GitHub Desktop.
Controller
<?php
namespace WebFactory\PurchaseBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use WebFactory\PurchaseBundle\Entity\Expense;
use WebFactory\PurchaseBundle\Form\ExpenseType;
use APY\DataGridBundle\Grid\Source\Entity;
use APY\DataGridBundle\Grid\Action\RowAction;
/**
* Expense controller.
*
* @Route("/expense")
*/
class ExpenseController extends Controller
{
/**
* Lists all Expense entities.
*
* @Route("/", name="expense")
* @Template()
*/
public function indexAction()
{
$source = new Entity('WebFactoryPurchaseBundle:Expense');
/* @var $grid \APY\DataGridBundle\Grid\Grid */
$grid = $this->get('grid');
$grid->setId('main');
$grid->setHiddenColumns(array('id'));
$grid->setSource($source);
$deleteRowAction = new RowAction('Delete', 'expense_delete', true, '_self', array('class' => 'grid_delete_action'));
$grid->addRowAction($deleteRowAction);
$editRowAction = new RowAction('Edit', 'expense_edit');
$grid->addRowAction($editRowAction);
$showRowAction = new RowAction('Show', 'expense_show');
$grid->addRowAction($showRowAction);
$grid->setActionsColumnSeparator("&nbsp;&nbsp;");
$grid->setActionsColumnSize(150);
$translator = $this->get('translator');
$source->manipulateRow(function($row) use ($translator) {
$row->setField('type', $translator->trans($row->getField('type')));
return $row;
});
return $grid->getGridResponse('WebFactoryPurchaseBundle:Expense:index.html.twig');
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment