You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sonata Admin:默认选中mosaic视图的实现方法

Set Mosaic View as Default in Sonata Admin (Keep List View Accessible)

Hey there! To make mosaic view the default display mode for your Sonata Admin entity while still keeping list view available for users to switch back to, follow these simple steps:

  • Locate your Admin class: Find the PHP class corresponding to your entity (e.g., ProductAdmin.php or whatever you've named it) in your project's Admin directory.

  • Update the configureListFields method: Inside this method, after defining your list fields, add the setDefaultView() call to set mosaic as the default. Here's an example:

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;

class YourEntityAdmin extends AbstractAdmin
{
    protected function configureListFields(ListMapper $listMapper)
    {
        // First, define your regular list fields as usual
        $listMapper
            ->add('id')
            ->add('title')
            ->add('createdAt')
            // ... add all your required fields
            
            // Set mosaic view as the default display mode
            ->setDefaultView('mosaic');
    }
}
  • Verify mosaic view is enabled: Make sure you've already configured the mosaic view for your entity (e.g., by adding mosaic-specific fields or setting up the necessary templates). If you haven't done this yet, you'll need to add that configuration first—otherwise, the mosaic view option won't appear at all.

Once you save these changes, when users navigate to the entity's list page, it will load the mosaic view by default. The list view toggle will still be visible in the top-right corner, so users can switch back whenever they need to.

内容的提问来源于stack exchange,提问作者c.bermon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:36:06