Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

toString method for SonataAdminBundle Listing in Symfony2

In Symfony 2.3 i am using SonataAdminBundle ( master ) and i am trying to get ManyToMany working in Listing. The Problem is that SonataAdminBundle is asking for a toString() method. Implementing this method to the related Entity solves the problem.

My Question: Do i have to implement the toString method or is there a Option to tell SonataAdminBundle a property for using instead of calling the toString method?

Thank you

like image 296
user2485214 Avatar asked Feb 15 '23 23:02

user2485214


1 Answers

As far as I know, it's mandatory.

But you can return another property value if you want. Also, you can prevent yourself from trying to display a property when the object has no data (for example, when you are "Adding a new object")

There is a simple way:

public function __toString()
{
    return ($this->getName()) ? : '';
}
like image 156
Dani Sancas Avatar answered Feb 23 '23 00:02

Dani Sancas