我有这样的形式:
class EntityType extends AbstractType
{
protected $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('category' , new CategoryType($this->em))
->add('entityTitle' , 'text', array(
'label' => 'Title',
'attr' => array('placeholder' => 'Title')
))
->add('entityDescription' , 'text', array(
'label' => 'Description',
'attr' => array('placeholder' => 'Description')
))
->add('entityStarttime', 'text', array(
'label' => 'Start Time',
'required' => false
))
->add('entityEndtime', 'text', array(
'label' => 'End Time',
'required' => false
))
->add('entityInstantsellingprice', 'money', array(
'label' => 'Instant Selling Price',
'attr' => array('placeholder' => 'Instant Selling Price')
))
->add('entityCondition', 'choice', array(
'choices' => array('n' => 'New', 'u' => 'Used'),
'label' => 'Condition',
'attr' => array('placeholder' => 'Condition')
))
;
}
public function getName()
{
return 'entity';
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Reuzze\ReuzzeBundle\Entity\Entities',
'validation_groups' => array('entity'),
));
}
}
我的实体类:
/**
* Entities
*
* @ORM\Table(name="entities", indexes={@ORM\Index(name="fk_entities_users1", columns={"user_id"}), @ORM\Index(name="fk_entities_countries1_idx", columns={"region_id"}), @ORM\Index(name="fk_entities_categories1_idx", columns={"category_id"})})
* @ORM\Entity
*/
class Entities
{
/**
* @var integer
*
* @ORM\Column(name="entity_id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $entityId;
/**
* @var string
*
* @ORM\Column(name="entity_title", type="string", length=255, nullable=false)
*/
private $entityTitle;
/**
* @var string
*
* @ORM\Column(name="entity_description", type="text", nullable=false)
*/
private $entityDescription;
/**
* @var \DateTime
*
* @ORM\Column(name="entity_starttime", type="datetime", nullable=false)
*/
private $entityStarttime;
/**
* @var \DateTime
*
* @ORM\Column(name="entity_endtime", type="datetime", nullable=false)
*/
private $entityEndtime;
/**
* @var string
*
* @ORM\Column(name="entity_instantsellingprice", type="decimal", precision=12, scale=2, nullable=false)
*/
private $entityInstantsellingprice;
/**
* @var string
*
* @ORM\Column(name="entity_shippingprice", type="decimal", precision=6, scale=2, nullable=true)
*/
private $entityShippingprice;
/**
* @var string
*
* @ORM\Column(name="entity_condition", type="string", nullable=false)
*/
private $entityCondition;
/**
* @var integer
*
* @ORM\Column(name="entity_views", type="bigint", nullable=true)
*/
private $entityViews;
/**
* @var \DateTime
*
* @ORM\Column(name="entity_created", type="datetime", nullable=false)
*/
private $entityCreated;
/**
* @var \DateTime
*
* @ORM\Column(name="entity_modified", type="datetime", nullable=true)
*/
private $entityModified;
/**
* @var \DateTime
*
* @ORM\Column(name="entity_deleted", type="datetime", nullable=true)
*/
private $entityDeleted;
/**
* @var \Reuzze\ReuzzeBundle\Entity\Users
*
* @ORM\ManyToOne(targetEntity="Reuzze\ReuzzeBundle\Entity\Users")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
* })
*/
private $user;
/**
* @var \Reuzze\ReuzzeBundle\Entity\Regions
*
* @ORM\ManyToOne(targetEntity="Reuzze\ReuzzeBundle\Entity\Regions")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="region_id", referencedColumnName="region_id")
* })
*/
private $region;
/**
* @var \Reuzze\ReuzzeBundle\Entity\Categories
*
* @ORM\ManyToOne(targetEntity="Reuzze\ReuzzeBundle\Entity\Categories")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="category_id", referencedColumnName="category_id")
* })
*/
private $category;
/**
* Get entityId
*
* @return integer
*/
public function getEntityId()
{
return $this->entityId;
}
/**
* Set entityTitle
*
* @param string $entityTitle
* @return Entities
*/
public function setEntityTitle($entityTitle)
{
$this->entityTitle = $entityTitle;
return $this;
}
/**
* Get entityTitle
*
* @return string
*/
public function getEntityTitle()
{
return $this->entityTitle;
}
/**
* Set entityDescription
*
* @param string $entityDescription
* @return Entities
*/
public function setEntityDescription($entityDescription)
{
$this->entityDescription = $entityDescription;
return $this;
}
/**
* Get entityDescription
*
* @return string
*/
public function getEntityDescription()
{
return $this->entityDescription;
}
/**
* Set entityStarttime
*
* @param \DateTime $entityStarttime
* @return Entities
*/
public function setEntityStarttime($entityStarttime)
{
$this->entityStarttime = $entityStarttime;
return $this;
}
/**
* Get entityStarttime
*
* @return \DateTime
*/
public function getEntityStarttime()
{
return $this->entityStarttime;
}
/**
* Set entityEndtime
*
* @param \DateTime $entityEndtime
* @return Entities
*/
public function setEntityEndtime($entityEndtime)
{
$this->entityEndtime = $entityEndtime;
return $this;
}
/**
* Get entityEndtime
*
* @return \DateTime
*/
public function getEntityEndtime()
{
return $this->entityEndtime;
}
/**
* Set entityInstantsellingprice
*
* @param string $entityInstantsellingprice
* @return Entities
*/
public function setEntityInstantsellingprice($entityInstantsellingprice)
{
$this->entityInstantsellingprice = $entityInstantsellingprice;
return $this;
}
/**
* Get entityInstantsellingprice
*
* @return string
*/
public function getEntityInstantsellingprice()
{
return $this->entityInstantsellingprice;
}
/**
* Set entityShippingprice
*
* @param string $entityShippingprice
* @return Entities
*/
public function setEntityShippingprice($entityShippingprice)
{
$this->entityShippingprice = $entityShippingprice;
return $this;
}
/**
* Get entityShippingprice
*
* @return string
*/
public function getEntityShippingprice()
{
return $this->entityShippingprice;
}
/**
* Set entityCondition
*
* @param string $entityCondition
* @return Entities
*/
public function setEntityCondition($entityCondition)
{
$this->entityCondition = $entityCondition;
return $this;
}
/**
* Get entityCondition
*
* @return string
*/
public function getEntityCondition()
{
return $this->entityCondition;
}
/**
* Set entityViews
*
* @param integer $entityViews
* @return Entities
*/
public function setEntityViews($entityViews)
{
$this->entityViews = $entityViews;
return $this;
}
/**
* Get entityViews
*
* @return integer
*/
public function getEntityViews()
{
return $this->entityViews;
}
/**
* Set entityCreated
*
* @param \DateTime $entityCreated
* @return Entities
*/
public function setEntityCreated($entityCreated)
{
$this->entityCreated = $entityCreated;
return $this;
}
/**
* Get entityCreated
*
* @return \DateTime
*/
public function getEntityCreated()
{
return $this->entityCreated;
}
/**
* Set entityModified
*
* @param \DateTime $entityModified
* @return Entities
*/
public function setEntityModified($entityModified)
{
$this->entityModified = $entityModified;
return $this;
}
/**
* Get entityModified
*
* @return \DateTime
*/
public function getEntityModified()
{
return $this->entityModified;
}
/**
* Set entityDeleted
*
* @param \DateTime $entityDeleted
* @return Entities
*/
public function setEntityDeleted($entityDeleted)
{
$this->entityDeleted = $entityDeleted;
return $this;
}
/**
* Get entityDeleted
*
* @return \DateTime
*/
public function getEntityDeleted()
{
return $this->entityDeleted;
}
/**
* Set user
*
* @param \Reuzze\ReuzzeBundle\Entity\Users $user
* @return Entities
*/
public function setUser(\Reuzze\ReuzzeBundle\Entity\Users $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \Reuzze\ReuzzeBundle\Entity\Users
*/
public function getUser()
{
return $this->user;
}
/**
* Set region
*
* @param \Reuzze\ReuzzeBundle\Entity\Regions $region
* @return Entities
*/
public function setRegion(\Reuzze\ReuzzeBundle\Entity\Regions $region = null)
{
$this->region = $region;
return $this;
}
/**
* Get region
*
* @return \Reuzze\ReuzzeBundle\Entity\Regions
*/
public function getRegion()
{
return $this->region;
}
/**
* Set category
*
* @param \Reuzze\ReuzzeBundle\Entity\Categories $category
* @return Entities
*/
public function setCategory(\Reuzze\ReuzzeBundle\Entity\Categories $category = null)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* @return \Reuzze\ReuzzeBundle\Entity\Categories
*/
public function getCategory()
{
return $this->category;
}
}
/**
* Entities
*
* @ORM\Table(name="entities", indexes={@ORM\Index(name="fk_entities_users1", columns={"user_id"}), @ORM\Index(name="fk_entities_countries1_idx", columns={"region_id"}), @ORM\Index(name="fk_entities_categories1_idx", columns={"category_id"})})
* @ORM\Entity
*/
class Entities
{
/**
* @var integer
*
* @ORM\Column(name="entity_id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $entityId;
/**
* @var string
*
* @ORM\Column(name="entity_title", type="string", length=255, nullable=false)
*/
private $entityTitle;
/**
* @var string
*
* @ORM\Column(name="entity_description", type="text", nullable=false)
*/
private $entityDescription;
/**
* @var \DateTime
*
* @ORM\Column(name="entity_starttime", type="datetime", nullable=false)
*/
private $entityStarttime;
/**
* @var \DateTime
*
* @ORM\Column(name="entity_endtime", type="datetime", nullable=false)
*/
private $entityEndtime;
/**
* @var string
*
* @ORM\Column(name="entity_instantsellingprice", type="decimal", precision=12, scale=2, nullable=false)
*/
private $entityInstantsellingprice;
/**
* @var string
*
* @ORM\Column(name="entity_shippingprice", type="decimal", precision=6, scale=2, nullable=true)
*/
private $entityShippingprice;
/**
* @var string
*
* @ORM\Column(name="entity_condition", type="string", nullable=false)
*/
private $entityCondition;
/**
* @var integer
*
* @ORM\Column(name="entity_views", type="bigint", nullable=true)
*/
private $entityViews;
/**
* @var \DateTime
*
* @ORM\Column(name="entity_created", type="datetime", nullable=false)
*/
private $entityCreated;
/**
* @var \DateTime
*
* @ORM\Column(name="entity_modified", type="datetime", nullable=true)
*/
private $entityModified;
/**
* @var \DateTime
*
* @ORM\Column(name="entity_deleted", type="datetime", nullable=true)
*/
private $entityDeleted;
/**
* @var \Reuzze\ReuzzeBundle\Entity\Users
*
* @ORM\ManyToOne(targetEntity="Reuzze\ReuzzeBundle\Entity\Users")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
* })
*/
private $user;
/**
* @var \Reuzze\ReuzzeBundle\Entity\Regions
*
* @ORM\ManyToOne(targetEntity="Reuzze\ReuzzeBundle\Entity\Regions")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="region_id", referencedColumnName="region_id")
* })
*/
private $region;
/**
* @var \Reuzze\ReuzzeBundle\Entity\Categories
*
* @ORM\ManyToOne(targetEntity="Reuzze\ReuzzeBundle\Entity\Categories")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="category_id", referencedColumnName="category_id")
* })
*/
private $category;
/**
* Get entityId
*
* @return integer
*/
public function getEntityId()
{
return $this->entityId;
}
/**
* Set entityTitle
*
* @param string $entityTitle
* @return Entities
*/
public function setEntityTitle($entityTitle)
{
$this->entityTitle = $entityTitle;
return $this;
}
/**
* Get entityTitle
*
* @return string
*/
public function getEntityTitle()
{
return $this->entityTitle;
}
/**
* Set entityDescription
*
* @param string $entityDescription
* @return Entities
*/
public function setEntityDescription($entityDescription)
{
$this->entityDescription = $entityDescription;
return $this;
}
/**
* Get entityDescription
*
* @return string
*/
public function getEntityDescription()
{
return $this->entityDescription;
}
/**
* Set entityStarttime
*
* @param \DateTime $entityStarttime
* @return Entities
*/
public function setEntityStarttime($entityStarttime)
{
$this->entityStarttime = $entityStarttime;
return $this;
}
/**
* Get entityStarttime
*
* @return \DateTime
*/
public function getEntityStarttime()
{
return $this->entityStarttime;
}
/**
* Set entityEndtime
*
* @param \DateTime $entityEndtime
* @return Entities
*/
public function setEntityEndtime($entityEndtime)
{
$this->entityEndtime = $entityEndtime;
return $this;
}
/**
* Get entityEndtime
*
* @return \DateTime
*/
public function getEntityEndtime()
{
return $this->entityEndtime;
}
/**
* Set entityInstantsellingprice
*
* @param string $entityInstantsellingprice
* @return Entities
*/
public function setEntityInstantsellingprice($entityInstantsellingprice)
{
$this->entityInstantsellingprice = $entityInstantsellingprice;
return $this;
}
/**
* Get entityInstantsellingprice
*
* @return string
*/
public function getEntityInstantsellingprice()
{
return $this->entityInstantsellingprice;
}
/**
* Set entityShippingprice
*
* @param string $entityShippingprice
* @return Entities
*/
public function setEntityShippingprice($entityShippingprice)
{
$this->entityShippingprice = $entityShippingprice;
return $this;
}
/**
* Get entityShippingprice
*
* @return string
*/
public function getEntityShippingprice()
{
return $this->entityShippingprice;
}
/**
* Set entityCondition
*
* @param string $entityCondition
* @return Entities
*/
public function setEntityCondition($entityCondition)
{
$this->entityCondition = $entityCondition;
return $this;
}
/**
* Get entityCondition
*
* @return string
*/
public function getEntityCondition()
{
return $this->entityCondition;
}
/**
* Set entityViews
*
* @param integer $entityViews
* @return Entities
*/
public function setEntityViews($entityViews)
{
$this->entityViews = $entityViews;
return $this;
}
/**
* Get entityViews
*
* @return integer
*/
public function getEntityViews()
{
return $this->entityViews;
}
/**
* Set entityCreated
*
* @param \DateTime $entityCreated
* @return Entities
*/
public function setEntityCreated($entityCreated)
{
$this->entityCreated = $entityCreated;
return $this;
}
/**
* Get entityCreated
*
* @return \DateTime
*/
public function getEntityCreated()
{
return $this->entityCreated;
}
/**
* Set entityModified
*
* @param \DateTime $entityModified
* @return Entities
*/
public function setEntityModified($entityModified)
{
$this->entityModified = $entityModified;
return $this;
}
/**
* Get entityModified
*
* @return \DateTime
*/
public function getEntityModified()
{
return $this->entityModified;
}
/**
* Set entityDeleted
*
* @param \DateTime $entityDeleted
* @return Entities
*/
public function setEntityDeleted($entityDeleted)
{
$this->entityDeleted = $entityDeleted;
return $this;
}
/**
* Get entityDeleted
*
* @return \DateTime
*/
public function getEntityDeleted()
{
return $this->entityDeleted;
}
/**
* Set user
*
* @param \Reuzze\ReuzzeBundle\Entity\Users $user
* @return Entities
*/
public function setUser(\Reuzze\ReuzzeBundle\Entity\Users $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* @return \Reuzze\ReuzzeBundle\Entity\Users
*/
public function getUser()
{
return $this->user;
}
/**
* Set region
*
* @param \Reuzze\ReuzzeBundle\Entity\Regions $region
* @return Entities
*/
public function setRegion(\Reuzze\ReuzzeBundle\Entity\Regions $region = null)
{
$this->region = $region;
return $this;
}
/**
* Get region
*
* @return \Reuzze\ReuzzeBundle\Entity\Regions
*/
public function getRegion()
{
return $this->region;
}
/**
* Set category
*
* @param \Reuzze\ReuzzeBundle\Entity\Categories $category
* @return Entities
*/
public function setCategory(\Reuzze\ReuzzeBundle\Entity\Categories $category = null)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* @return \Reuzze\ReuzzeBundle\Entity\Categories
*/
public function getCategory()
{
return $this->category;
}
}
我还有一个Table Media:
在我看来,我现在有:
<form novalidate="novalidate" id="form-Entity" method="post">
<fieldset>
<legend>Entity Page</legend>
<dl>
<dd class="form-group">
{{ form_row (form.entityTitle, { 'attr': {'class': 'form-control'} }) }}
{{ form_errors(form.entityTitle) }}
</dd>
<dd class="form-group">
{{ form_row (form.entityDescription, { 'attr': {'class': 'form-control'} }) }}
{# form_errors (form.password) #}
</dd>
<dd class="form-group">
{{ form_row (form.entityStarttime, { 'attr': {'class': 'form-control datepicker'} }) }}
{# form_errors (form.password) #}
</dd>
<dd class="form-group">
{{ form_row (form.entityEndtime, { 'attr': {'class': 'form-control datepicker'} }) }}
{# form_errors (form.password) #}
</dd>
<dd class="form-group">
{{ form_row (form.entityInstantsellingprice, { 'attr': {'class': 'form-control'} }) }}
{# form_errors (form.password) #}
</dd>
<dd class="form-group">
{{ form_row (form.entityCondition, { 'attr': {'class': 'form-control'} }) }}
{# form_errors (form.password) #}
</dd>
<dd class="form-group">
{{ form_row (form.category.categoryName, { 'attr': {'class': 'form-control'} }) }}
{{ form_errors (form.category.categoryName) }}
</dd>
<dd class="form-group">
<input class="form-control" id="fileupload" type="file" name="entity[files]" data-url="{{ oneup_uploader_endpoint('gallery') }}" multiple />
</dd>
</dl>
</fieldset>
{{ form_rest(form)}}
<p><input class="btn btn-primary" name="" type="submit" value="Create Entity!"></p>
</form>
正如您所见,我手动将<input class="form-control" id="fileupload" type="file" name="entity[files]" data-url="{{ oneup_uploader_endpoint('gallery') }}" multiple />
添加到我的表单中,因为我无法在我的formtype中使用媒体(不在entites类中)。
上传工作正常,但是当我在控制器中检查$ _POST时,文件不包括在内。我怎么能包括这个?
更新 来自$ _POST的var_dump告诉我:
array (size=1)
'entity' =>
array (size=8)
'entityTitle' => string 'sdqqsdsqd' (length=9)
'entityDescription' => string 'sqdssqd' (length=7)
'entityStarttime' => string '2014/01/22 00:00' (length=16)
'entityEndtime' => string '2014/01/18 00:00' (length=16)
'entityInstantsellingprice' => string '12' (length=2)
'entityCondition' => string 'n' (length=1)
'category' =>
array (size=1)
'categoryName' => string '1' (length=1)
'_token' => string 'oiflDN-Y0QPQrRzW9IIM8lB37LDbUQBvdR4LitsF2Ks' (length=43)
答案 0 :(得分:1)
在表单中添加enctype =“multipart / form-data”。
<form novalidate="novalidate" id="form-Entity" method="post" enctype="multipart/form-data">