Symfony Sonata管理员通过某些领域找到

时间:2015-08-19 14:14:12

标签: php symfony amazon-s3 sonata-admin symfony-sonata

我安装SonataAdminBundle并创建控制器扩展Admin和功能configureFormFields,configureDatagridFilters,configureListFields。在字段列表中我使用字段图像,但我只看到图像的网址,我的图像生活在亚马逊S3我希望在表格中看到图像。我是怎么做到的我有过colums查找过滤器,我的实体开发人员有阵列技能,并且通过一项技能找到了好的但是如何找到两个或多个技能?

我添加为管理员可以为开发人员上传头像但在我的行动(不是扩展管理员)我上传这样的(在开发人员=字符串中的字段图像,我只为S3设置了网址)

        $url = sprintf(
        '%s%s',
        $this->container->getParameter('acme_storage.amazon_s3.base_url'),
        $this->getPhotoUploader()->upload($request->files->get('file'), $user_company_name)
    );

    $user->setImage($url);

如何为奏鸣曲,重装控制器做些什么?我是怎么做到的

这是我的行动:

class DeveloperAdmin extends Admin
{

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper

        ->add('firstName', null, array('label' => 'Developer\'s First Name', 'max_length' => 255))
        ->add('lastName', null, array('label' => 'Developer\'s Last Name', 'max_length' => 255))
        ->add('qualification', 'choice', array('label' => 'Speciality',
            'choices' => array('Frontend' => 'Frontend', 'Backend' => 'Backend', 'Full stack' => 'Full stack'),'attr'=> array('class'=>'qualif'), 'required' => false))
        ->add('level', 'choice', array('label' => 'Professional Level', 'max_length' => 255,
            'choices' => array('Junior' => 'Junior', 'Middle' => 'Middle', 'Senior' => 'Senior')))
        ->add('tags', 'tags', array('label' => 'Tags','required' => false))
        ->add('main_skill', 'mainSkill', array('label' => 'Main Skill', 'required' => true, 'mapped' => true, 'attr' => array('placeholder' => 'Select your skills ...', 'class'=>'main_skill') ))
        ->add('skills', 'skills', array('label' => 'Skills','required' => false))
        ->add('english', 'choice', array('label' => 'English Level', 'max_length' => 255,
            'choices' => array('Basic' => 'Basic', 'Intermediate' => 'Intermediate', 'Advanced' => 'Advanced')))
        ->add('rate', null, array('label' => 'Rate $/h', 'max_length' => 255));
         $image = $this->getSubject();

    $fileFieldOptions = array('required' => false);

    if ($image && ($webPath = $image->getImage())) {
        dump($image);exit; //I have all user and field image local url /temp/sdgsdg          
        $container = $this->getConfigurationPool()->getContainer();
        $fullPath = $container->get('request')->getBasePath().'/'.$webPath;
        $fileFieldOptions['help'] = '<img src="'.$fullPath.'" class="admin-preview" />';
    }

    $formMapper
        ->add('image', 'file', $fileFieldOptions)
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $datagridMapper
        ->add('firstName')
        ->add('lastName')
        ->add('main_skill')
        ->add('skills')
    ;
}
protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('id')
        ->add('username')
        ->add('firstName')
        ->add('lastName')
        ->add('main_skill')
        ->add('skills')
        ->add('image', 'string', array('template' => 'SonataMediaBundle:MediaAdmin:list_image.html.twig'))

        ->add('_action', 'actions', array(
            'actions' => array(
                'show' => array(),
                'edit' => array(),
            )
        ))
    ;
}

}

如何通过两种或多种技能找到???? 这是我的实体:

class Developer extends CustomUser
{
/**
 * @var string
 *
 * @ORM\Column(name="email", type="string", length=255,  unique=false, nullable=true)
 * @Assert\Length(min=3, max=255)
 */
protected $email;
////
/**
 * @var string
 *
 * @ORM\Column(name="skills", type="array")
 */
private $skills = array();

在表格中,我的开发人员在colum技能中看到:

[0 => SOAP] [1 => Cisco] [2 => PHP] [3 => Sugar Crm] [4 => Hibernate] [5 => Java ME] 

但是当我添加开发者时,我使用我的服务技能,我看到了常规技能:

xPHP, xJava 

如何解决此问题,重新加载模板或控制器?请帮忙

1 个答案:

答案 0 :(得分:1)

对于此任务,请使用https://sonata-project.org/bundles/media/2-2/doc/index.html。这很容易