Jihed Jaouabi
Jihed Jaouabi

Reputation: 194

Displaying item id in sonata admin bundle

I created an admin interface using sonatadminbundle, it works fine & can add items & display them, but I also need to display the item id set by default (set as auto-increment) in the admin interface, how can I do that? admin dahsboard

Upvotes: 1

Views: 1579

Answers (2)

repincln
repincln

Reputation: 2049

Add id in $listMapper in your Acme/DemoBundle/Admin/somethingAdmin.php file:

protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('name')
            ->add('id')
        ;
    }

Upvotes: 3

toooni
toooni

Reputation: 345

you can do that using the __toString() method in the Entity (in your example Category) like:

function __toString()
{
    return $this->getId().' - '.$this->getName();
}

Upvotes: 3

Related Questions