Coder Social home page Coder Social logo

Comments (3)

cedric-g avatar cedric-g commented on July 19, 2024

Hi, you should not provide an abstract class as data_class because of the Form framework will try to create an instance of the data_class if no data object is provided when the form is created. And the bundle don't need a data_class to work, in my case most of time I set the data_class to null for a form type that is dedicated to filtering.

from lexikformfilterbundle.

L0rD59 avatar L0rD59 commented on July 19, 2024

@cedric-g thx for reply,

with

public function setDefaultOptions(OptionsResolver\OptionsResolverInterface $resolver)
    {
        parent::setDefaultOptions($resolver);

        $resolver->setDefaults(array(
            'data_class' => null,
        ));
    }

that's work, but the field "Type" who corresponding to my discriminator map does'nt work

so i've trying to add a apply_filter like that :

$builder
            ->add('type', 'filter_choice', array(
                'choices' => $typeChoices,
                'apply_filter' => function(LexikFormFilterBundle\Filter\Query\QueryInterface $filterQuery, $field, $values)
                {
                    $filterQuery->getQueryBuilder()->add('where', 'u.type = :u_type')->setParameter(':u_type', $values['value']);

                    return $filterQuery;
                }
            ))

but i got this error :

An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 58 near 'type = :u_ty': Error: Class LIG\Bundle\UserBundle\Entity\User has no field or association named type")

i've same error with or without the apply_filter

thx for your help

from lexikformfilterbundle.

L0rD59 avatar L0rD59 commented on July 19, 2024

k that's work now

$builder
            ->add('type', 'filter_choice', array(
                'choices' => $typeChoices,
                'apply_filter' => function(LexikFormFilterBundle\Filter\Query\QueryInterface $filterQuery, $field, $values)
                {
                    $filterQuery->getQueryBuilder()->add('from', 'LIG\Bundle\UserBundle\Entity\User'.$values['value'].' '.$values['alias']);
                    return $filterQuery;
                }
            ))

from lexikformfilterbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.