zenside/sonata-image-bundle

允许在sonata forms中轻松支持图像上传,并在一对一中预览当前图像

安装: 60

依赖者: 0

建议者: 0

安全: 0

星星: 1

关注者: 2

分支: 3

开放问题: 1

类型:symfony-bundle

dev-master 2017-03-17 12:48 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:37:05 UTC


README

允许轻松将图像属性添加到实体,以便包含在Sonata Forms中。

安装

使用composer添加bundle

composer require zenside/sonata-image-bundle

并在AppKernel.php中引用它

new ZenSide\SonataImageBundle\ZenSideSonataImageBundle(),

配置

下载后将bundle添加到AppKernel后,更新您的数据库以添加图像实体

php app/console doctrine:schema:update --force

然后您可以在实体中添加到图像类型的关联

class Article {
    /**
     * @ORM\OneToOne(targetEntity="ZenSide\SonataImageBundle\Entity\Image", cascade={"persist"})
     * @ORM\JoinColumn(nullable=true, onDelete="set null")
     */
    private $image;
}

如果您想在SonataAdmin类中直接使用它,只需使用类型为 'sonata_type_admin' 或 'sonata_type_model' 的字段

$form->add('logo', 'sonata_type_admin');

重要:如果您使用 'sonata_type_admin' 在表单中直接包含输入类型文件,必须在您的Admin类中添加以下preUpdate和prePersist监听器。

只需将以下行复制到您的Admin类中

public function prePersist($subject)
{
    ImageAdmin::manageEmbeddedImageAdmins($this, $subject);
}
public function preUpdate($subject)
{
    ImageAdmin::manageEmbeddedImageAdmins($this, $subject);
}