奏鸣曲给田野上色

sonata color the fields

我想了解奏鸣曲的工作原理,但我有一个问题。我在他们的演示中看到了一些不错的东西,但我在他们的文档中找不到喜欢做的事情。也许你能帮帮我。

在字段中,他们根据标准确定颜色值,后者的值我想知道该怎么做。我在他们的网站上放了一个小屏幕,也许可以帮助您理解我的请求。

我有一个小表格,我也放了代码,我希望能够将 "client" 涂成绿色,红色 "ex-client" 和蓝色 "prospect" 怎么样我应该怎么做?

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->tab('General Information',array('class'=>'col-md-9'))
        ->with('', array('class'=>'col-md-9'))
        ->add('firstName', 'text')
        ->add('surname', 'text')
        ->add('address', 'text',array('required'=> false))
        ->add('email', 'email', array(
            'required' => false))
        ->add('Phone', 'text', array(
            'required' => false))
        ->add('birthdate', 'birthday', array('label' => 'Date of Birth','required'=>false))
        ->end()
        ->with('Others Informations',array('class'=>'col-md-3'))
        ->add('Status', 'choice', array(
            'choices' => array(
                'Client' => 'Client',
                'Ex-Client' => 'Ex-Client',
                'Prospect' => 'Prospect'),
        ))
        ->add('businessname', 'text', array('label' => 'Business Name','required'=>false))
        ->add('typeofbusiness', 'choice', array(
            'choices' => array(
                'Blank' => Null,
                'SE' => 'SE',
                'SA' => 'SA',
                'LLP' => 'LLP',
                'LTD' => 'LTD',
                'Payroll' => 'Payroll'),
            'label' => 'Type of buisness'
        ))
        ->end()
        ->end()
        ->tab('Comment',array('class'=>'col-md-12'))
        ->add('comments', 'textarea', array('required'=>false))
        ->end()
    ;
}



protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $datagridMapper
        ->add('surname')
        ->add('firstname')
        ->add('address')
        ->add('email')
        ->add('phone')
        ->add('birthdate', null, array(
            'label' => 'Date of birth (mm/dd/yyyy)'), 'sonata_type_datetime_picker', array(
            'format'                => 'MM/dd/yyyy',
            'dp_side_by_side'       => true,
            'dp_use_current'        => false,
            'dp_use_seconds'        => false,
        ))
        ->add('status')
        ->add('businessname')
        ->add('typeofbusiness')
        ->add('comments')
    ;

}

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('surname')
        ->add('firstname')
        ->add('address')
        ->add('email')
        ->add('phone')
        ->add('birthdate')
        ->add('Status')
        ->add('businessname')
        ->add('typeofbusiness')
        ->add('comments');
}

public function toString($object)
{
    return $object instanceof Client
        ? $object->getSurname()
        : 'Client'; // shown in the breadcrumb on the create view
}

}

同样在安装和控制中,他们让我们创建了一个 BlogPost,但我没有在任何地方定义任何东西,布尔值是红色或绿色的。我真的不知道该怎么做。

您可以通过为您的字段创建自定义模板来做到这一点

看这里:https://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/list_field_definition.html#custom-template