HI, please help
In my app development need to add an upload file like is shown in the Sonata demo bundle, car item when offer the option of associate a file
Here is the code about the entity car.php
<?php
namespace Sonata\Bundle\DemoBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Sonata\MediaBundle\Model\MediaInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\Table(name="test_car")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({
* "renault" = "Renault",
* "citroen" = "Citroen",
* "peugeot" = "Peugeot"
* })
*/
abstract class Car
{
…
…
…
/**
* @var \AppBundle\Entity\Media\Media
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Media\Media", cascade={"persist"}, fetch="LAZY")
*/
protected $media;
public function __construct()
{
$this->inspections = new ArrayCollection();
}
/**
…
…
…
/**
* @return \AppBundle\Entity\Media\Media
*/
public function getMedia()
{
return $this->media;
}
/**
* @param \AppBundle\Entity\Media\Media $media
*/
public function setMedia(MediaInterface $media = null)
{
$this->media = $media;
}
/**
* @return string
*/
public function __toString()
{
return $this->getName() ?: 'n/a';
}
}
This the entity in my app
<?php
namespace Intranet\Pni\OeuBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Sonata\MediaBundle\Model\MediaInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* SoporteFormalCambios
*
* @ORM\Table(name="soporte_formal_cambios", indexes={@ORM\Index(name="idx_tipo_soporte_formal_cambios", columns={"id_tipo_soporte_formal_cambios"})})
* @ORM\Entity
*/
class SoporteFormalCambios
{
…
…
…
/**
* @var \AppBundle\Entity\Media\Media
* @ORM\ManyToOne(targetEntity="\AppBundle\Entity\Media\Media", cascade={"persist"}, fetch="LAZY")
*/
protected $media;
…
…
…
/**
* @return \AppBundle\Entity\Media\Media
*/
public function getMedia()
{
return $this->media;
}
/**
* @param \AppBundle\Entity\Media\Media $media
*/
public function setMedia(MediaInterface $media = null)
{
$this->media = $media;
}
}
now the admin controllers
<?php
amespace Sonata\Bundle\DemoBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\Bundle\DemoBundle\Entity\Inspection;
/**
* @author Thomas Rabaix <
thomas...@sonata-project.org>
*/
class CarAdmin extends Admin
{
…
…
…
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
…
…
…
->with('Options', array('class' => 'col-md-7'))
->add('engine', 'sonata_type_model_list')
->add('color', 'sonata_type_model_list')
->add('media', 'sonata_media_type', array(
'provider' => 'sonata.media.provider.image',
'context' => 'default',
))
->end()
…
…
…
;
}
}
?>
this is the admin controller on my app
<?php
namespace Intranet\Pni\OeuBundle\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Vich\UploaderBundle\Form\Type\VichFileType;
use Sonata\AdminBundle\Route\RouteCollection;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Sonata\Bundle\DemoBundle\Entity\Inspection;
class SoporteFormalCambiosAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
…
…
…
->add('media', 'sonata_media_type',
array(
'provider' => 'sonata.media.provider.image',
'context' => 'default',
)
)
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'AppBundle\Intranet\Pni\OeuBundle\Entity\SoporteFormalCambios',
)
);
}
…
…
…
}
in other words this parameterized files are relatively similar but I get the following error:
An exception has been thrown during the rendering of a template ("The class 'AppBundle\Entity\Media\Media' was not found in the chain configured namespaces Intranet\Pni\OeuBundle\Entity").
What I m forgetting? How I have to configure the chain of configured namespaces?
Some Clue?