i ve got two classes : template and templateparameters.
Here is the code for the first one :
<?php
namespace HPI\DisplayBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Template
*
* @ORM\Table(name="HPI_template")
* @ORM\Entity
*/
class Template
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="templatelabel", type="string", length=255)
*/
private $templatelabel;
/**
* @var string
*
* @ORM\Column(name="templatedescription", type="text")
*/
private $templatedescription;
/**
* @var string
*
* @ORM\Column(name="templatefile", type="string", length=255)
*/
private $templatefile;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set templatelabel
*
* @param string $templatelabel
* @return Template
*/
public function setTemplatelabel($templatelabel)
{
$this->templatelabel = $templatelabel;
return $this;
}
/**
* Get templatelabel
*
* @return string
*/
public function getTemplatelabel()
{
return $this->templatelabel;
}
/**
* Set templatedescription
*
* @param string $templatedescription
* @return Template
*/
public function setTemplatedescription($templatedescription)
{
$this->templatedescription = $templatedescription;
return $this;
}
/**
* Get templatedescription
*
* @return string
*/
public function getTemplatedescription()
{
return $this->templatedescription;
}
/**
* Set templatefile
*
* @param string $templatefile
* @return Template
*/
public function setTemplatefile($templatefile)
{
$this->templatefile = $templatefile;
return $this;
}
/**
* Get templatefile
*
* @return string
*/
public function getTemplatefile()
{
return $this->templatefile;
}
public function __toString() {
return $this->templatelabel;
}
}
And here is the code for the second one :
namespace HPI\DisplayBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* TemplateParameters
*
* @ORM\Table(name="HPI_templateparameters")
* @ORM\Entity
*/
class TemplateParameters
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="parametername", type="string", length=255)
*/
private $parametername;
/**
*
* @ORM\ManyToOne(targetEntity="Template")
* @ORM\JoinColumn(nullable=false)
*/
private $template;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set parametername
*
* @param string $parametername
* @return TemplateParameters
*/
public function setParametername($parametername)
{
$this->parametername = $parametername;
return $this;
}
/**
* Get parametername
*
* @return string
*/
public function getParametername()
{
return $this->parametername;
}
/**
* Set template
*
* @param \HPI\DisplayBundle\Entity\Template $template
* @return TemplateParameters
*/
public function setTemplate(\HPI\DisplayBundle\Entity\Template $template)
{
$this->template = $template;
return $this;
}
/**
* Get template
*
* @return \HPI\DisplayBundle\Entity\Template
*/
public function getTemplate()
{
return $this->template;
}
}
As you can notice there is a manytoone relationships between theses 2 classes
I ve created a relevant service in my config.yml
sonata.admin.templateparameters:
class: HPI\AdminBundle\Models\TemplateParametersAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: "Marketing", label: "Template Parameters" }
arguments:
- ~
- HPI\DisplayBundle\Entity\TemplateParameters
- ~
When i want to add a new parameter in the sonata admin, using directly the templateparameters admin i've got no problem. But as soon as i want to add it as a collection in the template admin, i've got the following message : The current field parametername
is not linked to an admin. Please create one for the target entity : ``
So as i mentionned i'm sure that the admin is existing, cause i can use it by acting directly on it. Anyone got an idea ? i went through several topics here but it's not really clear to me how they solved this problem.
I had the same issue and resolved it by creating admin for the field as you did for TemplateParametersAdmin and changing the $formMapper as following:
->add('sos', 'sonata_type_model',
[
'property' => 'title',
'multiple' => true,
'by_reference' => false,
'attr' => ['style' => 'width: 100%;']
]
)
The type 'sonata_type_model' actually makes a difference.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.