Symfony 3 Sonata Admin 使用注释创建管理员

Symfony 3 Sonata Admin create admin using annotation

我尝试仅使用来自 JMSDiExtraBundle 的注释来创建奏鸣曲管理员。

管理员:

/**
 * @DI\Service("sonata.admin.company")
 * @DI\Tag("sonata.admin", attributes = {
 *     "manager_type" = "orm",
 *     "label"="Category",
 *     "group"="Orders"
 *      })
 */
class CompanyAdmin extends Admin
{
    /**
     * @DI\InjectParams({
     *     "code" = @DI\Inject("%admin__company__class%"),
     *     "class" = @DI\Inject("%admin__company__code%"),
     *     "baseControllerName" = @DI\Inject("%admin__company__base_controller_name%")
     * })
     */
    public function __construct($code, $class, $baseControllerName)
    {
        parent::__construct($code, $class, $baseControllerName);
    }
}

和参数文件:

parameters:
#    parameter_name: value
    admin__company__class: AppBundle\Entity\Company
    admin__company__base_controller_name: SonataAdminBundle:CRUD
    admin__company__code: admin.company

当我在 yml 中注册管理员时它可以工作,但使用注释号。

汤姆

正如 JMSDiExtraBundle 的文档所述:

By default, you can only use the provided annotations on your non-service controllers; no other directories are scanned.

However, if you also would like to use annotations to configure your regular services, you can configure more locations as demonstrated below.

If you would like to configure services in a bundle of yours via annotations, or have some services outside of any bundles structure such as in your src/ directory, you can make use of the following configuration options, so that the bundle will pick them up, and add them to your dependency injection container:

jms_di_extra:
    locations:
        all_bundles: false
        bundles: [FooBundle, AcmeBlogBundle]
        directories: ["%kernel.root_dir%/../src"]