The Show View
Now your admin allows you to create, edit and list blog posts and categories. But what if you just want to have a detailed view of one blog? This chapter will teach you how to use the show view.
If you're still on http://localhost:8000/admin/app/blogpost/list, you'll see a show button on every blog post row. But when you click on it, you end up with a "No form available" message. This is because Sonata doesn't know which fields to show, let's now configure some.
Configuring the Show Mapper
If you're now familiar with the FormMapper
and the ListMapper
, the
ShowMapper
will look very similar:
1 2 3 4 5 6 7 8 9 10 11 12 13
// src/Admin/BlogPostAdmin.php
use Sonata\AdminBundle\Show\ShowMapper;
protected function configureShowFields(ShowMapper $show): void
{
$show
->add('id')
->add('title')
->add('body')
->add('category.name')
;
}
Using Groups and tabs
Like the FormMapper
, the ShowMapper
also supports grouping fields together:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// src/Admin/BlogPostAdmin.php
protected function configureShowFields(ShowMapper $show): void
{
$show
->tab('Post')
->with('Content', ['class' => 'col-md-9'])
// ...
->end()
->with('Meta data', ['class' => 'col-md-3'])
// ...
->end()
->end()
->tab('Publish Options')
// ...
->end()
;
}
Round Up
You've learned how to find posts to edit, how to create a nice list view, how to add options to search, order and filter this list. Now you've learned how to display the details of one post.
There might have been some very difficult things, but imagine the difficulty writing everything yourself! As you're now already quite good with the basics, you can start reading other articles in the documentation, like: