したがって、多くの調査を行った後、結果が得られませんでした (おそらく私は下手な検索者です) 私は次のトピックから来ました: SonataAdmin Bundle File Upload Error and SonataMediaBundle - how to upload images? 問題の解決策が見つかりません。私はエンティティを持っておりCompany
、各会社は複数のファイルを持つことができます: PDF、DOC、XLS、その他の MIME/タイプ。私はVichUploaderBundleを使用することを考えていますが、ドキュメントは 1 対 1 の関係の例のみをカバーしているため、私の質問は、これを実現するための例や方法を教えてくれる人はいますか? ファイルをアップロードして会社に添付するということですか?
EDIT1 の作業とテスト
前に言ったように、SonataMediaBundle を別の管理モジュールに統合しようとしていますが、機能させることができません。私は今まで何をしていましたか?
もちろん、すべてのバンドルをインストールして構成します。SonataAdminBundle と SonataMediaBundle はどちらも正常に動作しています。
ManyToMany\Application\Sonata\MediaBundle\Entity\Media.php
関係を追加することにより、必要な機能を追加するように変更されたクラス
namespace Application\Sonata\MediaBundle\Entity;
use Sonata\MediaBundle\Entity\BaseMedia as BaseMedia;
use Doctrine\ORM\Mapping as ORM;
class Media extends BaseMedia {
/**
* @var integer $id
*/
protected $id;
/**
* @ORM\ManyToMany(targetEntity="PL\OrderBundle\Entity\Order", inversedBy="medias")
* @ORM\JoinTable(name="order_has_media__media",
* joinColumns={@ORM\JoinColumn(name="media__media_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="order_no_order", referencedColumnName="no_order")}
* )
*/
protected $orders;
public function __construct() {
$this->orders = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer $id
*/
public function getId() {
return $this->id;
}
public function setOrders(\PL\OrderBundle\Entity\Order $order) {
$this->orders[] = $order;
}
public function getOrders() {
return $this->orders;
}
}
次のように PL\OrderBundle\Entity\Order.php に必要なフィールドを追加します。
namespace PL\OrderBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="tb_order")
*/
class Order {
/**
* @ORM\Id
* @ORM\Column(type="string", length=15, unique=true, nullable=false)
*/
protected $no_order;
/**
* @ORM\ManyToOne(targetEntity="PL\CompanyBundle\Entity\Company", inversedBy="id")
*/
protected $company;
/**
* @ORM\Column(type="string", length=15, unique=true)
*/
protected $business_case;
/**
* @ORM\Column(type="integer", length=1)
*/
protected $charge_status;
/**
* @ORM\Column(type="datetime")
*/
protected $eta;
/**
* @ORM\Column(type="datetime")
*/
protected $etd;
/**
* @ORM\Column(type="integer", length=1)
*/
protected $transport_media;
/**
* @ORM\Column(type="integer", length=1)
*/
protected $incoterm;
/**
* @ORM\Column(type="string", length=250)
*/
protected $comments;
/**
* @ORM\ManyToMany(targetEntity="Application\Sonata\MediaBundle\Entity\Media", mappedBy="orders")
*/
protected $medias;
public function __construct() {
$this->medias = new \Doctrine\Common\Collections\ArrayCollection();
}
public function setNoOrder($no_order) {
$this->no_order = $no_order;
}
public function getNoOrder() {
return $this->no_order;
}
public function setCompany(\PL\CompanyBundle\Entity\Company $company) {
$this->company = $company;
}
public function getCompany() {
return $this->company;
}
public function setBusinessCase($business_case) {
$this->business_case = $business_case;
}
public function getBusinessCase() {
return $this->business_case;
}
public function setChargeStatus($charge_status) {
$this->charge_status = $charge_status;
}
public function getChargeStatus() {
return $this->charge_status;
}
public function setETA($eta) {
$this->eta = $eta;
}
public function getETA() {
return $this->eta;
}
public function setETD($etd) {
$this->etd = $etd;
}
public function getETD() {
return $this->etd;
}
public function setTransportMedia($transport_media) {
$this->transport_media = $transport_media;
}
public function getTransportMedia() {
return $this->transport_media;
}
public function setIncoterm($incoterm) {
$this->incoterm = $incoterm;
}
public function getIncoterm() {
return $this->incoterm;
}
public function setComments($comments) {
$this->comments = $comments;
}
public function getComments() {
return $this->comments;
}
public function setMedias(\Application\Sonata\MediaBundle\Entity\Media $media) {
$this->medias[] = $media;
}
public function addMedia(\Application\Sonata\MediaBundle\Entity\Media $media) {
$this->medias[] = $media;
}
public function getMedias() {
return $this->medias;
}
}
OrderAdmin.php ファイルの configureFormFields を次のように変更しました。
protected function configureFormFields(FormMapper $form) {
$form
->add('no_order', null, array('label' => 'No. Order'))
->add('company', 'entity', array('class' => 'PL\CompanyBundle\Entity\Company', 'label' => 'Cliente'))
->add('business_case', null, array('label' => 'BC'))
->add('charge_status', 'choice', array('choices' => array(
"empty_value" => "Seleccione una opción",
"0" => "Ninguno",
"1" => "Proceso de Fabricacion",
"2" => "Pickup en destino",
"3" => "A la espera de recojo por cliente",
"4" => "Carga en transito",
"5" => "Carga arribada",
"6" => "En proceso de aduana",
"7" => "Entregado a cliente",
"8" => "En bodega"
), "required" => true, 'label' => 'Estado de la carga'))
->add('eta', null, array('label' => 'ETD'))
->add('etd', null, array('label' => 'ETA'))
->add('transport_media', 'choice', array('choices' => array("empty_value" => "Seleccione una opción", "0" => "EXW", "1" => "Maritimo", "2" => "Aereo"), "required" => true, 'label' => 'Via de Transporte'))
->add('incoterm', 'choice', array('choices' => array(
"empty_value" => "Seleccione una opción",
"0" => "Ninguno",
"1" => "EWX",
"2" => "FOB",
"3" => "CIF",
"4" => "DDP"
), "required" => true, 'label' => 'Incoterm'))
->add('comments', null, array('label' => 'Comentarios'))
->add('medias', 'sonata_type_collection', array(
'label' => 'Documentos',
'type_options' => array('delete' => true)), array(
'edit' => 'inline', 'inline' => 'table', 'sortable' => 'position')
);
}
しかし、ファイルをアップロードできないため、これは機能しません。これは、同じフォームから多くのファイルをアップロードし、作成中の注文に添付したいものです。作成アクションにアクセスしたときに取得するビジュアルについては、添付の画像を参照してください。
私は何が欠けていますか?