Reputation: 424
I am getting error when I am using following entity type field, It is showing me select field fine but when I am trying to save it it is giving me following error
Code 1:
->add('agentFirstname', 'entity', array(
'class' => 'AcmeClientBundle:Client',
'property' => 'firstName',
))
Error 1: Catchable Fatal Error: Object of class Acme\ClientBundle\Entity\Client could not be converted to string
When I am using second code then everything is working fine
Code 2:
->add('agentFirstname', 'text', array(
)
)
Error 2: No Error
Please find my entity bellow
/**
* @var string
*
* @ORM\Column(name="agent_firstname", type="string", length=255)
*/
private $agentFirstname;
I want to make select field here for client first name entity which is here
/**
* @var string
*/
private $firstName;
Upvotes: 0
Views: 94
Reputation: 2110
Symfony cannot access the $firstName
property as its visibility is private.
You need to add a getFirstName()
method to your Acme\ClientBundle\Entity\Client class.
public function getFirstName()
{
return $this->firstName;
}
Now change your form code to:
->add('agentFirstname', 'entity', array(
'class' => 'AcmeClientBundle:Client', 'property' => 'getFirstName'
))
Upvotes: 1