APY / APYDataGridBundle

Symfony Datagrid Bundle
MIT License
492 stars 343 forks source link

data() function don't work on Twig 1.2.0 and Symfony 2.0.5 #52

Closed henriqueboaventura closed 12 years ago

henriqueboaventura commented 12 years ago

After update twig ans symfony, the datagrid bundle stopped working. It display the message:

An exception has been thrown during the rendering of a template ("[Syntax Error] line 0, col 77: Error: Expected =, <, <=, <>, >, >=, !=, got '('") in "GestorSistemaBundle:Country:index.html.twig" at line 1.

There is only one line on my template:

{{ grid(data) }}

The template don't extends any other template.

ghost commented 12 years ago

i'll look into it asap

btw data in your example is a grid instance not function

Abhoryo commented 12 years ago

Are you sure about your twig version because I can't find Twig 1.0.2 version.

ethanhann commented 12 years ago

I am experiencing the same error with Symfony 2.0.5, but my Twig version is 1.1.2.

Abhoryo commented 12 years ago

Hum, me too but another error. (I use a modified bundle)

[Syntax Error] line 0, col 60: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '__base__' 

And with the original bundle :

[Syntax Error] line 0, col 74: Error: Expected =, <, <=, <>, >, >=, !=, got '(' 

I'll try to understand why.

henriqueboaventura commented 12 years ago

The right version is 1.2.0, sorry about that.

Abhoryo commented 12 years ago

Try this new version.

Abhoryo commented 12 years ago

Hum, wait for @Sorien because nothing works :D

@Sorien, data are not shown because getId() is use instead of getField() in dataGridExtension.php

And filters don't work anymore too. Can you correct your mess :D

ghost commented 12 years ago

i've just updated to symfony 2.05 and everything is working as before in all my tests

ghost commented 12 years ago

did you cleanup all the cache after update?

Abhoryo commented 12 years ago

Of course the cache is updated.

Can you past your controller code and your entity?

Maybe a problem with the ID of column not defined with an annotation in the entity?

ghost commented 12 years ago

entity (without getter/setters)

namespace Base\Invoice\Entity;

use Doctrine\ORM\Mapping as ORM;
use Sorien\DataGridBundle\Grid\Mapping as GRID;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Base\Invoice\Entity\Items
 *
 * @ORM\Table(name="invoice_suppliers")
 * @ORM\Entity
 * @GRID\Column(id="callbacks", size="36", type="blank", role="ROLE_ADMIN", align="right")
 */
class InvoiceSupplier
{
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @GRID\Column(visible=false)
     */
    private $id;

    /**
     * @ORM\Column(name="name_test", type="string", length=100) // test different table column name and property
     * Assert\NotBlank()
     * @GRID\Column(title="Názov")
     */
    private $name;

    /**
     * @ORM\Column(name="address", type="string", length=100, nullable=true)
     * @GRID\Column(title="Adresa", visible=false)
     */
    private $address;

    /**
     * @ORM\Column(name="town", type="string", length=50, nullable=true)
     * @GRID\Column(title="Mesto", visible=false)
     */
    private $town;

    /**
     * @ORM\Column(name="zip", type="string", length=10, nullable=true)
     * @GRID\Column(title="Psč", visible=false)
     */
    private $zip;

    /**
     * @ORM\Column(name="state", type="string", length=20, nullable=true)
     * @GRID\Column(title="Štát", visible=false)
     */
    private $state;

    /**
     * @ORM\Column(name="ico", type="string", length=10, nullable=true)
     * Assert\Regex(pattern="/[0-9]{8}/", message="IČO musí obsahovať osem číslic")
     * @GRID\Column(title="IČO", size="100", visible=false)
     */
    private $ico;

    /**
     * @ORM\Column(name="dic", type="string", length=12, nullable=true)
     * Assert\Regex(pattern="/[0-9]{10}/", message="DIČ musí obsahovať desať číslic")
     * @GRID\Column(title="DIČ", size="100")
     */
    private $dic;

    /**
     * @ORM\Column(name="icdph", type="string", length=12, nullable=true)
     * @GRID\Column(title="IČ DPH", size="100", visible=false)
     */
    private $icdph;

    /**
     * @ORM\Column(name="phone", type="string", length=20, nullable=true)
     * @GRID\Column(title="Telefón", size="150")
     */
    private $phone;

    /**
     * @ORM\Column(name="email", type="string", length=40, nullable=true)
     * @GRID\Column(title="Email", size="150")
     */
    private $email;

    /**
     * @ORM\Column(name="contact", type="string", length=100, nullable=true)
     * @GRID\Column(title="Kontakt", size="200")
     */
    private $contact;

    /**
     * @ORM\Column(name="bank_account", type="string", length=20, nullable=true)
     * @GRID\Column(title="Účet", size="200")
     */
    private $bank_account;
    /**
     * @ORM\Column(name="swift", type="string", length=20, nullable=true)
     * @GRID\Column(title="SWIFT", size="20", visible=false)
     */
    private $swift;

    /**
     * @ORM\Column(name="iban", type="string", length=40, nullable=true)
     * @GRID\Column(title="IBAN", size="200", visible=false)
     */
    private $iban;

    /**
     * @ORM\Column(name="description", type="string", length=200, nullable=true)
     * @GRID\Column(title="Description", size="500", visible=false)
     */
    private $description;   
}

controller

public function indexAction()
{
    $grid = $this->get('grid')->setSource(new Entity('Invoice:InvoiceSupplier'));

    if ($grid->isReadyForRedirect())
    {
        return new RedirectResponse($this->generateUrl('admin_invoice_supplier'));
    }
    else
    {
        return $this->render('Invoice:InvoiceSupplier:index.html.twig', array('data' => $grid));
    }
}

twig

{{ grid(data) }}
Abhoryo commented 12 years ago

I'll try this tonight.

You test this with my last commit ?

ghost commented 12 years ago

yes, like every another grid in my current project

ghost commented 12 years ago

guys can you give me a simple entity which is causing problems?

Abhoryo commented 12 years ago

A problem I see when I debug the code, $colum->getId() is always empty. and if getId() is empty, data are not put in the grid.

ghost commented 12 years ago

another annotations are loaded correctly orm/asserts?

any cache activated for doctrine, php version?

ghost commented 12 years ago

grid\mapping\driver\annotation is id set after line 103?

id is set according class property name, if not set in annotation, I'm not sure what can cause your problems

ethanhann commented 12 years ago

After updating the bundle from the repo this morning I am now getting this error: An exception has been thrown during the rendering of a template ("The "CCITWildfireBundle_mailing" route has some missing mandatory parameters ("id").") in "SorienDataGridBundle::blocks.html.twig" at line 4.

I will post my code shortly.

ethanhann commented 12 years ago

URL: http://localhost/proj/app_dev.php/default/1

Route:

AcmeTestBundle_default:
    pattern:  /default/{id}
    defaults: { _controller: AcmeTestBundle:Default:index }

Controller:

namespace Acme\TestBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sorien\DataGridBundle\Grid\Source\Entity;

class DefaultController extends Controller
{    
    public function indexAction($id)
    {   
        $source = new Entity('AcmeTestBundle:Sample');
        $grid = $this->get('grid');
        $grid->setSource($source);       
        return $this->render('AcmeTestBundle::test.html.twig', array('data' => $grid));
    }
}

Template:

{{ grid(data) }}
ethanhann commented 12 years ago

If I remove the id parameter from the route and the indexAction function the grid renders without an error.

Abhoryo commented 12 years ago

This is an other error.

ethanhann commented 12 years ago

Would you like me to open a separate issue?

Abhoryo commented 12 years ago

@Sorien If you don't use a column annonation on a field. The column is displayed without data.

Abhoryo commented 12 years ago

@ethanhann can you open a new issue for the route problem?

Filter redirection doesn't handle route parameters.

ghost commented 12 years ago

@Abhoryo ok, noted, i'll look into it tomorrow

ghost commented 12 years ago

@If you don't use a column annonation on a field. The column is displayed without data

fixed by last commit

@kidh0 still you have same error?

henriqueboaventura commented 12 years ago

@S0RIEN everything works just fine now

ghost commented 12 years ago

ok, closing