Symfony更改属性名称

时间:2015-07-30 14:13:35

标签: symfony sonata-admin

我有两个实体:

/**
* Device
*
* @ORM\Table(name="device", indexes={@ORM\Index(name="referente_id",    columns={"referente_id"})})
* @ORM\Entity
*/
class Device
{
/**
 * @var string
 *
 * @ORM\Column(name="id_device", type="string", length=60)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $idDevice;

/**
 * @var \Doctrine\Common\Collections\Collection
 *
 * @ORM\ManyToMany(targetEntity="Acme\BasicCmsBundle\Entity\Carrier", mappedBy="device")
 */
private $carrier;

/**
* Carrier
*
* @ORM\Table(name="carrier")
* @ORM\Entity
*/
class Carrier
{
/**
 * @var string
 *
 * @ORM\Column(name="rag_soc", type="string", length=200, nullable=true)
 */
private $ragSoc;

/**
 * @var string
 *
 * @ORM\Column(name="via", type="string", length=150, nullable=true)
 */
private $via;

/**
 * @var string
 *
 * @ORM\Column(name="nr", type="string", length=8, nullable=true)
 */
private $nr;

/**
 * @var string
 *
 * @ORM\Column(name="citta", type="string", length=100, nullable=true)
 */
private $citta;

/**
 * @var string
 *
 * @ORM\Column(name="naz", type="string", length=5, nullable=true)
 */
private $naz;

/**
 * @var string
 *
 * @ORM\Column(name="tel", type="string", length=20, nullable=true)
 */
private $tel;

/**
 * @var integer
 *
 * @ORM\Column(name="id_carrier", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $idCarrier;

/**
 * @var \Doctrine\Common\Collections\Collection
 *
 * @ORM\ManyToMany(targetEntity="Acme\BasicCmsBundle\Entity\Device", inversedBy="carrier")
 * @ORM\JoinTable(name="carrier_device",
 *   joinColumns={
 *     @ORM\JoinColumn(name="carrier_id", referencedColumnName="id_carrier")
 *   },
 *   inverseJoinColumns={
 *     @ORM\JoinColumn(name="device_id", referencedColumnName="id_device")
 *   }
 * )
 */
private $device;

实体具有多对多关系。我创建了管理页面:

class CarrierAdmin extends Admin
{
protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('rag_soc', 'string')
        ->addIdentifier('citta', 'string')
        ->add('device', null, array('associated_property' => 'id_device'))
        ->add('_action', 'actions', array(
            'actions' => array(
                'view' => array(),
                'edit' => array(),
                'delete' => array(),
            )
        ));
}

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->with('Carrier Information', array('class' => 'col-md-8', 'box_class'   => 'box box-solid box-danger', 'description' => 'Lorem ipsum',))
            ->add('rag_soc', 'text')
            ->add('citta', 'text')
        ->end()
        ->with('Devices', array('class' => 'col-md-8', 'box_class'   => 'box box-solid box-danger', 'description' => 'Lorem ipsum',))
            ->add('device', 'sonata_type_model_autocomplete', array('property'=>'idDevice', 'multiple' => true,))
            ->end();
}


protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $datagridMapper->add('ragSoc');
    $datagridMapper->add('citta', null, array('show_filter'=>true))
    ->add('device');
}

protected function configureShowFields(ShowMapper $showMapper)
{
   $showMapper->add('rag_soc');
}

class DeviceAdmin extends Admin
{
protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('idDevice', 'string');
}

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->with('form.group_general', array('class' => 'col-md-8', 'box_class'   => 'box box-solid box-danger', 'description' => 'Lorem ipsum',))
        ->add('idDevice', 'text')
    ->end();
}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $datagridMapper->add('idDevice');
}

public function getExportFormats()
{
    return array();
}
}

在CarrierAdmin中,我在表单中将设备项定义为sonata_type_model_autocomplete。我的问题是添加或删除设备会导致“找不到属性”异常。 Symfony将属性名称从Device更改为Devouce。

错误在PropertyAccessor:writeProperty函数中,调用StringUtil::singularify($camelized)来更改属性名称。

这是一个错误吗?

我暂时通过将原始属性名称添加到StringUtil::singularify($camelized)的结果中来解决它。

0 个答案:

没有答案