0
VichUploader를 사용하여 Symfony 3 응용 프로그램에서 파일 업로드를 관리하고 있습니다. 이제 파일/엔터티 삭제 관리 방법을 궁금해하십니까? 응용 프로그램의Symfony/VichUploaderBundle : 엔티티 제거
발췌/설정/config.yml : 엔티티의
vich_uploader:
db_driver: orm
mappings:
upload_artists:
uri_prefix: /upload/artists
upload_destination: %kernel.root_dir%/../web/upload/artists
directory_namer: artist_directory_namer
namer: vich_uploader.namer_uniqid
inject_on_load: false
delete_on_update: true
delete_on_remove: true
발췌 : 컨트롤러의
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity
* @ORM\Table(name="image_file")
* @Vich\Uploadable
*/
class ImageFile {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
*/
private $title;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="upload_artists", fileNameProperty="imageName")
*
* @var File
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $imageName;
/**
* @ORM\Column(type="datetime")
*
* @var \DateTime
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity="Artist")
* @ORM\JoinColumn(name="artist_id", referencedColumnName="id")
*/
private $artist;
/**
* @ORM\Column(type="boolean")
*/
private $deleted;
발췌 :
namespace Acme\Bundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Acme\Bundle\Entity\Artist;
use Acme\Bundle\Entity\ImageFile;
class ArtistPhotoController extends Controller {
// ...
public function deleteDisabledAction($id = null) {
$artist = $this->getDoctrine()
->getRepository('Bundle:Artist')
->find($id)
;
$repository = $this->getDoctrine()->getRepository('Bundle:ImageFile');
$photosDisabled = $repository->findBy(array('artist' => $artist, 'application' => $this->application, 'deleted' => 1), array('updatedAt' => 'DESC'));
$counter = 0;
foreach ($photosDisabled as $disabled) {
if($disabled->remove()) {
$counter++;
}
}
if ($counter > 0) {
$this->addFlash(
'success',
$counter.' items successfully deleted!'
);
}
}
}
... ' $ disabled-> remove() '는 테스트 일 뿐이며 오류 메시지가 나타납니다 ("undefined method remove"). VichUploader에서 관리하는 파일/엔티티를 삭제/삭제하는 올바른 방법은 무엇입니까? 어떤 힌트? 미리 감사드립니다.
감사합니다. 내 문제가 해결되었습니다. 나는 Symfony를 처음 접했고 vichuploader 문서 대신에 교리를 보는 아이디어를 찾지 못했습니다. – Pixelrocker