简体   繁体   English

Symfony2-奏鸣曲管理员。 在字段表单实体中显示颜色表

[英]Symfony2 - Sonata Admin. Show color table in field form entity

I'm using Sonata Admin to administrate some of my entites on my web application. 我正在使用Sonata Admin在Web应用程序上管理某些实体。 One of them is 'accessLevel'. 其中之一是“ accessLevel”。 One of its fields is 'color' that is a VARCHAR(6) on my MYSQL database and I use on the 'style= background-color: #{{ color }}' tag on its TWIG. 它的字段之一是'color',它是我的MYSQL数据库上的VARCHAR(6),我在其TWIG的'style = background-color:#{{color}}'标签上使用。 I would like, if it were possible, to show a color table when I create or edit my 'accessLevel' entity to choose one and store its hexadecimal value on the database. 如果可能,我希望在创建或编辑“ accessLevel”实体以选择一个并将其十六进制值存储在数据库中时显示颜色表。

Any suggestions? 有什么建议么?

You should probably use Genemu JQueryColor Field 您可能应该使用Genemu JQueryColor字段

<?php
// ...
public function buildForm(FormBuilder $builder, array $options)
{
    $builder
        // ...
        ->add('color', 'genemu_jquerycolor')
        ->add('colorpicker', 'genemu_jquerycolor', array(
            'widget' => 'image'
    ))
}

I use this bundle with SonataAdmin, and everything works fine. 我将此捆绑包与SonataAdmin结合使用,一切正常。

Have a look at the doc to see what you can do with this bundle. 看一下文档 ,看看可以使用此捆绑软件做什么。

Don't forget to update your template to add javascript and css files. 不要忘了更新模板以添加javascript和css文件。 See this link 看到这个链接

Hope this is what you want 希望这就是你想要的

in the master version of sonata core bundle i found this 在奏鸣曲核心捆绑的主版本中,我发现了这个

# app/config/config.yml
twig:
    form:
        resources:
            - 'SonataCoreBundle:Form:colorpicker.html.twig'

and the configureFormFields will be like this : 和configureFormFields将是这样的:

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->add('color', 'sonata_type_color_selector')
        // ...
    ;
}

I hope that help ! 希望对我有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM