I have a table which has relationship with Application\Sonata\MediaBundle\Entity\Media (SonataMediaBundle Entity) as 'media'
Normally I can make the form for Media like this below,
$form = $this->createFormBuilder($myMedia)
->add('name')
->add('media') // make the selectbox
->add('save', SubmitType::class, array('label' => 'Create Post'))
->getForm();
However I want to restrict to some medias from all medias, then I made this.
$form = $this->createFormBuilder($myMedia)
->add('name')
->add('media','entity',array(
'class' => "Application\Sonata\MediaBundle\Entity\Media",
'query_builder' => function(EntityRepository $er) {
return $er->createQuery('SELECT r FROM ApplicationSonataMediaBundle:Media');
}))
->add('save', SubmitType::class, array('label' => 'Create Post'))
->getForm();
However it shows the error like this.
Undefined method 'createQuery'. The method name must start with either findBy or findOneBy!
I have found some articles and understood it is related with Repository.
But I am not sure which Repository should I point. THere is no Repository class under
Sonata\MediaBundle\
either Application\Sonata\MediaBundle
namespace Application\Sonata\MediaBundle\Entity;
use Sonata\MediaBundle\Entity\BaseMedia as BaseMedia;
@ORM\Entity(repositoryClass="Where is my repository???")
class Media extends BaseMedia
{
/**
* @var int $id
*/
protected $id;
BTW, my first code shows only select box for pictures(medias)
It is not useful enough to select pictures, Is there a more suitable way for selecting pictures?