Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine
This tutorial has a new version, check it out!

Views & entities Config

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

With EasyAdminBundle, you can configure just about everything... in multiple different ways. It's great! But also confusing. So, let's get it straight!

There are two different axis for configuring things. First, every entity has 5 different "views": list - which is this one - search, new, edit and show. Each view can be configured. Second, each entity can also be configured. And sometimes, these overlap: you can tweak something for all list views, but then override that list tweak for one specific entity.

Global list Config

Let's see this in action! In config.yml, under easy_admin, you can configure the list view by adding a list key. Set title: 'List':

... lines 1 - 80
easy_admin:
... lines 82 - 86
list:
title: 'List'
... lines 89 - 94

And yep! Each view can be configured like this, by adding search, show, edit or new. Some config, like title, will work under all of these. But mostly, each section has its own config.

When you add list at this root level, it applies to all entities. Try it out: yes! We just added a boring title to all the list pages!

For more context, add a magic wildcard: %%entity_label%%:

... lines 1 - 80
easy_admin:
... lines 82 - 86
list:
title: 'List of %%entity_label%%'
... lines 89 - 94

Try it! Much better!

There are just a few magic wildcards: entity_label, entity_name and entity_id. The entity_name is the geeky, machine-name for your entity - like GenusNote. The entity_label defaults to that same value... but we can change it to something better.

Configuring at the Entity Level

So far, we just have a simple list of all the entity admin sections we want. That's great to get started... but not anymore! As soon as you need to configure an entity further, you need to use an expanded format. Basically, instead of - Genus, use Genus as the key and add a new line with class set to the full class name: AppBundle\Entity\Genus:

... lines 1 - 80
easy_admin:
... lines 82 - 88
entities:
Genus:
class: AppBundle\Entity\Genus
... lines 92 - 98

Repeat this for everything else: GenusNote, SubFamily and User:

... lines 1 - 80
easy_admin:
... lines 82 - 88
entities:
Genus:
class: AppBundle\Entity\Genus
GenusNote:
class: AppBundle\Entity\GenusNote
SubFamily:
class: AppBundle\Entity\SubFamily
User:
class: AppBundle\Entity\User

This didn't change anything... but now we are, oh yes, dangerous! Oh, so much can be configured for each entity. Start simple: label: Genuses:

... lines 1 - 80
easy_admin:
... lines 82 - 88
entities:
Genus:
class: AppBundle\Entity\Genus
label: Genuses
... lines 93 - 99

Try that! Nice! The label is of course used in the title, but also in the navigation.

Overriding the List view under an Entity

And here's where things get really interesting. The list config we added applies to all entities. But we can also customize the list view for just one entity. Under GenusNote, add a label: 'Genus Notes':

... lines 1 - 80
easy_admin:
... lines 82 - 88
entities:
... lines 90 - 92
GenusNote:
class: AppBundle\Entity\GenusNote
label: Genus Notes
... lines 96 - 102

But more importantly, add list, then title: 'List of notes':

... lines 1 - 80
easy_admin:
... lines 82 - 88
entities:
... lines 90 - 92
GenusNote:
class: AppBundle\Entity\GenusNote
label: Genus Notes
list:
title: List of notes
... lines 98 - 102

Ok, check this out! The left navigation uses the new label. But the list page's title is List of notes.

Woohoo! To review: there are 5 views, and each view can be configured globally, but also beneath each entity. If that makes sense, you're in great shape.

The Search View

While we're here, go type a few letters into that search box. Yep! This is the search view. It's almost identical to list: it re-uses its template and has almost identical config keys.

Overriding Entity View Config

In addition to title, one other key that every view has is help. First, set this below the Genus section: "Genuses are not covered by warranty!":

... lines 1 - 80
easy_admin:
... lines 82 - 88
entities:
Genus:
... lines 91 - 92
help: Genuses are not covered under warranty!
... lines 94 - 103

Notice, this is directly under the entity config, not under a specific view. Thanks to this, it will apply to all views for this entity. And... yep! It's at the top of the search page, on list and on edit.

In the spirit of EasyAdminBundle, you can override this for each view below. For list, set help to Do not feed!:

... lines 1 - 80
easy_admin:
... lines 82 - 88
entities:
Genus:
... lines 91 - 92
help: Genuses are not covered under warranty!
list:
help: Do not feed!
... lines 96 - 105

Nice!

And the search view still uses the default message. If you want to turn off the help message here, you can totally do that. Under search, set help to null:

... lines 1 - 80
easy_admin:
... lines 82 - 88
entities:
Genus:
... lines 91 - 92
help: Genuses are not covered under warranty!
list:
help: Do not feed!
search:
help: null
... lines 98 - 107

Refresh! Gone!

Ok, so we're not going to talk about all of the different keys available: it's all pretty easy. The most important thing is to realize that each of the 5 views can be configured on two different levels.

Next, let's talk about actions and the different ones that we can enable.

Leave a comment!

5
Login or Register to join the conversation
Parham A. Avatar
Parham A. Avatar Parham A. | posted 3 years ago

Hello, would you please give me some hints how can I integrate my AWS DynamoDb with easyadmin ?

Reply

Hey Parham A.

I think it's not possible because EasyAdminBundle relies on Doctrine and it does not support DynamoDb, you can see all the platforms that Doctrine supports here: https://www.doctrine-projec...

You may want to ask this question in the repository https://github.com/EasyCorp...

Reply
Default user avatar
Default user avatar Tenchi Masaki | posted 5 years ago

Hello, I'm new in knpuniversity. I have a problem in user registration, what structure should the role column have?

Reply
Default user avatar

Never mind, is ["ROLE_ADMIN"]. I did not see the data fixtures.

Reply

Hey Tenchi Masaki

No worries, and welcome to Symfony!

Cheers :)

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

This tutorial is built on an older version of Symfony & EasyAdminBundle. Many of the concepts are the same, but you can expect major differences in newer versions.

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": ">=5.5.9",
        "symfony/symfony": "3.3.*", // v3.3.18
        "doctrine/orm": "^2.5", // v2.7.2
        "doctrine/doctrine-bundle": "^1.6", // 1.10.3
        "doctrine/doctrine-cache-bundle": "^1.2", // 1.3.5
        "symfony/swiftmailer-bundle": "^2.3", // v2.6.7
        "symfony/monolog-bundle": "^2.8", // v2.12.1
        "symfony/polyfill-apcu": "^1.0", // v1.17.0
        "sensio/distribution-bundle": "^5.0", // v5.0.25
        "sensio/framework-extra-bundle": "^3.0.2", // v3.0.29
        "incenteev/composer-parameter-handler": "^2.0", // v2.1.4
        "knplabs/knp-markdown-bundle": "^1.4", // 1.7.1
        "doctrine/doctrine-migrations-bundle": "^1.1", // v1.3.2
        "stof/doctrine-extensions-bundle": "^1.2", // v1.3.0
        "composer/package-versions-deprecated": "^1.11", // 1.11.99
        "javiereguiluz/easyadmin-bundle": "^1.16" // v1.17.21
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0", // v3.1.7
        "symfony/phpunit-bridge": "^3.0", // v3.4.40
        "nelmio/alice": "^2.1", // v2.3.5
        "doctrine/doctrine-fixtures-bundle": "^2.3" // v2.4.1
    }
}
userVoice