如何使用 Symfony2 和 SonataAdmin 从 mongodb 数据库上传图像?
How to upload an image from a mongodb database with Symfony2 and SonataAdmin?
我不确定这个问题是否适合出现在这里,但现在这是我最后的选择。
我在一个 symfony2 项目中工作,有一个奏鸣曲管理员和一个 mongodb 数据库。我们使用 Vich bundle 将图片上传到亚马逊服务器。
我有两张图片,一张正常工作,另一张不明原因。
当我尝试在 Sonata 管理中添加图片时,它根本不更新照片,或者只是保持空白。
这是正常工作的代码。
@我的文档
/**
* @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;
@我的管理员
->tab('images')
->with('OTHERS',['class' => 'col-md-6'])
->add('image_button_file', 'custom_image')
->end()
->end()
但是下面的代码没有
@我的文档
/**
* @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;
}
@我的管理员
->tab('images')
->with('OTHERS',['class' => 'col-md-6'])
->add('image_wordpress_header_file', 'custom_image')
->end()
->end()
至少有什么建议我该如何调试?
显然我应该在更改图像时更新文档。否则它不会更新数据库。我不知道为什么这发生在一个变量上而没有发生在另一个变量上。
public function setImage2lFile($image2lFile)
{
$this->image2l_file = $image2lFile;
if ($image2lFile) {
$this->setUpdatedAt(new \DateTime());
}
return $this;
}
我不确定这个问题是否适合出现在这里,但现在这是我最后的选择。
我在一个 symfony2 项目中工作,有一个奏鸣曲管理员和一个 mongodb 数据库。我们使用 Vich bundle 将图片上传到亚马逊服务器。
我有两张图片,一张正常工作,另一张不明原因。
当我尝试在 Sonata 管理中添加图片时,它根本不更新照片,或者只是保持空白。
这是正常工作的代码。
@我的文档
/**
* @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;
@我的管理员
->tab('images')
->with('OTHERS',['class' => 'col-md-6'])
->add('image_button_file', 'custom_image')
->end()
->end()
但是下面的代码没有
@我的文档
/**
* @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;
}
@我的管理员
->tab('images')
->with('OTHERS',['class' => 'col-md-6'])
->add('image_wordpress_header_file', 'custom_image')
->end()
->end()
至少有什么建议我该如何调试?
显然我应该在更改图像时更新文档。否则它不会更新数据库。我不知道为什么这发生在一个变量上而没有发生在另一个变量上。
public function setImage2lFile($image2lFile)
{
$this->image2l_file = $image2lFile;
if ($image2lFile) {
$this->setUpdatedAt(new \DateTime());
}
return $this;
}