doulu8341
2016-12-09 15:56
浏览 32
已采纳

如何使用Symfony2和SonataAdmin从mongodb数据库上传图像?

I don't know for sure if this question is fit to be here, but now that is my last option.

I am working in a symfony2 project, with a sonata admin and a mongodb database. We use Vich bundle to upload image to a amazon server.

I have two images, one is working normally, and the other not for some unknown reason.

When I try to add an image in the Sonata admin it simply doesn't update the photo, or simply keep in blank.

Here is the code of the one that is working normally.

@my document

/**
 * @var string
 *
 * @MongoDB\String
 * @Serializer\Since("2.0")
 */
protected $image_button;


/**
   * @Vich\UploadableField(mapping="folder_images", fileNameProperty="image_button")
   * @var File $image_button_file
   */
protected $image_button_file;


//GETTERS AND SETTERS

/**
 * Set imageButton
 *
 * @param string $imageButton
 * @return self
 */
public function setImageButton($imageButton)
{
    $this->image_button = $imageButton;
    return $this;
}

/**
 * Get imageButton
 *
 * @return string $imageButton
 */
public function getImageButton()
{
    return $this->image_button;
}



public function setImageButtonFile($imageButtonFile)
{
    $this->image_button_file = $imageButtonFile;
    if ($imageButtonFile) {
        $this->setUpdatedAt(new \DateTime());
    }
    return $this;
}


public function getImageButtonFile()
{
    return $this->image_button_file;

@my admin

->tab('images')
     ->with('OTHERS',['class' => 'col-md-6'])
     ->add('image_button_file', 'custom_image')
  ->end()
->end()

BUT the following code doesn't

@my document

/**
 * @var string
 *
 * @MongoDB\String
 * @Serializer\Since("2.0")
 */
protected $image_wordpress_header;

/**
 * @Vich\UploadableField(mapping="folder_images", fileNameProperty="image_wordpress_header")
 * @var File $image_wordpress_header_file
 */
protected $image_wordpress_header_file;


//GETTERS AND SETTERS

/**
 * @return string
 */
public function getImageWordpressHeader()
{
    return $this->image_wordpress_header;
}

/**
 * @param string $image_wordpress_header
 */
public function setImageWordpressHeader($image_wordpress_header)
{
    $this->image_wordpress_header = $image_wordpress_header;
}

/**
 * @return File
 */
public function getImageWordpressHeaderFile()
{
    return $this->image_wordpress_header_file;
}

/**
 * @param File $image_wordpress_header_file
 */
public function setImageWordpressHeaderFile($image_wordpress_header_file)
{
    $this->image_wordpress_header_file = $image_wordpress_header_file;

}

@my admin

->tab('images')
     ->with('OTHERS',['class' => 'col-md-6'])
     ->add('image_wordpress_header_file', 'custom_image')
  ->end()
->end()

There is any suggestion at least how could I debug that?

1条回答 默认 最新

相关推荐 更多相似问题