I install SonataAdminBundle and create controller extends Admin and function configureFormFields, configureDatagridFilters, configureListFields. And in field list I use field image but I see only url for image, my image live in amazon S3 I want see image in table. How I do this? And I have filter for find by colums, my entity developer have array skill and by one skill find good but how find for two or many skill ?
And I add for admin can do upload avatar for developer but in my action(not extends Admin) I upload like this for(field image in Developer = string and I set just url for 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);
how I can do for sonata, reload controller? How I do this ?
this my action:
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(),
)
))
;
}
}
How find by two or many skill ???? this is my entity:
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();
and in table for my developer in colum skill I see:
[0 => SOAP] [1 => Cisco] [2 => PHP] [3 => Sugar Crm] [4 => Hibernate] [5 => Java ME]
but when I add developer I use my service for skill and I see norm skill:
xPHP, xJava
How can fix this problem, reload template or controller ? Help please
For this task use https://sonata-project.org/bundles/media/2-2/doc/index.html . It's very easy
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.