Search code examples
sonata

Item "AdminBundle\Entity\Prize:000000046fa222" has been successfully created


hi i want with sonata to have an item using 'name' label. but not always the same.

i put this in admin class

public function toString($object) {
    if (!is_object($object)) {
        return '';
    }
    if (method_exists($object, '__toString') && null !== $object->__toString()) {
        return (string) $object;
    }

    $cname = explode('\\', get_class($object));
    return end($cname);
}

but it give always the same name. i want to have the label 'name' of each entity


Solution

  • You need to override the __toString() magic method in your entity class

    public function __toString(){
        return $this->name;    
    }