Symfony2嵌入了一系列表单(Symfony2 Embed a Collection of Forms)
嗨,我有形式嵌入的问题。 我有3个关系OneToMany的课程
StockTaking OneToMany StockTakingDetail ManyToOne Hardware
我提交表格时,我收到错误。 我不知道我犯了什么错误。
错误:
可捕获的致命错误:传递给AppBundle \ Entity \ MagazineStockTakingDetails :: setHardware()的参数1必须是AppBundle \ Entity \ Hardware的实例,给定的数组,在C:\ Projekty \ sla \ vendor \ symfony \ symfony \ src \ Symfony中调用第442行上的\ Component \ PropertyAccess \ PropertyAccessor.php并定义
我在下面编写了我的课程和表格。 请帮我找错。
namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Class MagazineStockTaking * @package AppBundle\Entity * @ORM\Entity() * @ORM\Table(name="sla_stocktaking") */ class MagazineStockTaking { /** * @ORM\Id * @ORM\Column(name="stockTakingId", type="integer", nullable=false) * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(name="stockinNumber", type="string", length=20, nullable=false) */ protected $stockingnumber; /** * @ORM\Column(name="stockinDate", type="datetime", nullable=false) */ protected $stockingdate; /** * @ORM\Column(name="stockingNote", type="string", length=1000, nullable=false) */ protected $stockingnote; //////////////////////////////////////////////// // RELACJE //////////////////////////////////////////////// /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Magazine", inversedBy="stocktaking") * @ORM\JoinColumn(name="magazine_id", referencedColumnName="magazineId", nullable=false) */ protected $magazine; /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="stocktaking") * @ORM\JoinColumn(name="user_id", referencedColumnName="userId", nullable=false) */ protected $user; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\MagazineStockTakingDetails", mappedBy="stocktaking", cascade={"persist"}) */ protected $details; //////////////////////////////////////////////// // GET SET //////////////////////////////////////////////// /** * Constructor */ public function __construct() { $this->details = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set stockingnumber * * @param string $stockingnumber * @return MagazineStockTaking */ public function setStockingnumber($stockingnumber) { $this->stockingnumber = $stockingnumber; return $this; } /** * Get stockingnumber * * @return string */ public function getStockingnumber() { return $this->stockingnumber; } /** * Set stockingdate * * @param \DateTime $stockingdate * @return MagazineStockTaking */ public function setStockingdate($stockingdate) { $this->stockingdate = $stockingdate; return $this; } /** * Get stockingdate * * @return \DateTime */ public function getStockingdate() { return $this->stockingdate; } /** * Set stockingnote * * @param string $stockingnote * @return MagazineStockTaking */ public function setStockingnote($stockingnote) { $this->stockingnote = $stockingnote; return $this; } /** * Get stockingnote * * @return string */ public function getStockingnote() { return $this->stockingnote; } /** * Set magazine * * @param \AppBundle\Entity\Magazine $magazine * @return MagazineStockTaking */ public function setMagazine(\AppBundle\Entity\Magazine $magazine) { $this->magazine = $magazine; return $this; } /** * Get magazine * * @return \AppBundle\Entity\Magazine */ public function getMagazine() { return $this->magazine; } /** * Set user * * @param \AppBundle\Entity\User $user * @return MagazineStockTaking */ public function setUser(\AppBundle\Entity\User $user) { $this->user = $user; return $this; } /** * Get user * * @return \AppBundle\Entity\User */ public function getUser() { return $this->user; } /** * Add details * * @param \AppBundle\Entity\MagazineStockTakingDetails $details * @return MagazineStockTaking */ public function addDetail(\AppBundle\Entity\MagazineStockTakingDetails $details) { $this->details[] = $details; return $this; } /** * Remove details * * @param \AppBundle\Entity\MagazineStockTakingDetails $details */ public function removeDetail(\AppBundle\Entity\MagazineStockTakingDetails $details) { $this->details->removeElement($details); } /** * Get details * * @return \Doctrine\Common\Collections\Collection */ public function getDetails() { return $this->details; } }
二等
<?php namespace AppBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; /** * Class MagazineStockTakingDetails * @package AppBundle\Entity * @ORM\Entity() * @ORM\Table(name="sla_stocktakingdetails") */ class MagazineStockTakingDetails { /** * @ORM\Id() * @ORM\Column(name="stackTakingDetailsId", type="integer", nullable=false) * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(name="hardwareCount", type="integer", nullable=false) */ protected $count = 1; ///////////////////////////////////////////// // RELACJE ///////////////////////////////////////////// /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\MagazineStockTaking", inversedBy="details") * @ORM\JoinColumn(name="stacktaking_id", referencedColumnName="stockTakingId", nullable=false) */ protected $stocktaking; /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Hardware", inversedBy="stocktakingdetails",cascade={"persist"}) * @ORM\JoinColumn(name="hardware_id", referencedColumnName="hardwareId", nullable=false) */ protected $hardware; ///////////////////////////////////////////// // GET SET ///////////////////////////////////////////// /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set count * * @param integer $count * @return MagazineStockTakingDetails */ public function setCount($count) { $this->count = $count; return $this; } /** * Get count * * @return integer */ public function getCount() { return $this->count; } /** * Set stocktaking * * @param \AppBundle\Entity\MagazineStockTaking $stocktaking * @return MagazineStockTakingDetails */ public function setStocktaking(\AppBundle\Entity\MagazineStockTaking $stocktaking) { $this->stocktaking = $stocktaking; return $this; } /** * Get stocktaking * * @return \AppBundle\Entity\MagazineStockTaking */ public function getStocktaking() { return $this->stocktaking; } /** * Set hardware * * @param \AppBundle\Entity\Hardware $hardware * @return MagazineStockTakingDetails */ public function setHardware(\AppBundle\Entity\Hardware $hardware) { $this->hardware = $hardware; return $this; } /** * Get hardware * * @return \AppBundle\Entity\Hardware */ public function getHardware() { return $this->hardware; } }
三等
<?php namespace AppBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation as JMS; use JMS\Serializer\Annotation\Groups; /** * Class Hardware * @package AppBundle\Entity * @ORM\Entity(repositoryClass="HardwareRepository", ) * @ORM\Table(name="sla_hardwares") * @JMS\ExclusionPolicy("all") */ class Hardware { /** * @ORM\Id() * @ORM\Column(name="hardwareId", type="integer", nullable=false) * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(name="hardwareSn", type="string", length=200, nullable=true) */ protected $sn; /** * @ORM\Column(name="hardwareGwarantyDate", type="datetime", nullable=true) */ protected $gwarantydate; /** * @ORM\Column(name="hardwareNote", type="string", length=750, nullable=true) */ protected $note; /** * @ORM\Column(name="hardwareIsReturned", type="boolean", nullable=false) */ protected $isreturned = false; //////////////////////////////////////// //// RELACJE //////////////////////////////////////// /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\HardwareProducent", inversedBy="hardware") * @ORM\JoinColumn(name="producent_id", referencedColumnName="producentId", nullable=false) */ protected $producent; /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\HardwareCategory", inversedBy="hardware") * @ORM\JoinColumn(name="category_id", referencedColumnName="hardwareCategoryId", nullable=false) */ protected $category; /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\HardwareModel", inversedBy="hardware") * @ORM\JoinColumn(name="model_id", referencedColumnName="hardwareModelId", nullable=false) */ protected $model; /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\HardwareStatus", inversedBy="hardware") * @ORM\JoinColumn(name="status_id", referencedColumnName="statusId", nullable=false) */ protected $status; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\HardwareStatusHistory", mappedBy="hardware") */ protected $statushistory; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\MagazineDetails", mappedBy="hardware") */ protected $magazine; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\MagazineShiftDetails", mappedBy="hardware") */ protected $magazineshift; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\MagazineUtilizeDetails", mappedBy="hardware") */ protected $utilize; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\MagazineStockTakingDetails", mappedBy="hardware", cascade={"persist"}) */ protected $stocktakingdetails; //////////////////////////////////////// //// GET SET //////////////////////////////////////// /** * Constructor */ public function __construct() { $this->statushistory = new \Doctrine\Common\Collections\ArrayCollection(); $this->magazine = new \Doctrine\Common\Collections\ArrayCollection(); $this->magazineshift = new \Doctrine\Common\Collections\ArrayCollection(); $this->utilize = new \Doctrine\Common\Collections\ArrayCollection(); $this->stocktakingdetails = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set sn * * @param string $sn * @return Hardware */ public function setSn($sn) { $this->sn = $sn; return $this; } /** * Get sn * * @return string */ public function getSn() { return $this->sn; } /** * Set gwarantydate * * @param \DateTime $gwarantydate * @return Hardware */ public function setGwarantydate($gwarantydate) { $this->gwarantydate = $gwarantydate; return $this; } /** * Get gwarantydate * * @return \DateTime */ public function getGwarantydate() { return $this->gwarantydate; } /** * Set note * * @param string $note * @return Hardware */ public function setNote($note) { $this->note = $note; return $this; } /** * Get note * * @return string */ public function getNote() { return $this->note; } /** * Set isreturned * * @param boolean $isreturned * @return Hardware */ public function setIsreturned($isreturned) { $this->isreturned = $isreturned; return $this; } /** * Get isreturned * * @return boolean */ public function getIsreturned() { return $this->isreturned; } /** * Set producent * * @param \AppBundle\Entity\HardwareProducent $producent * @return Hardware */ public function setProducent(\AppBundle\Entity\HardwareProducent $producent) { $this->producent = $producent; return $this; } /** * Get producent * * @return \AppBundle\Entity\HardwareProducent */ public function getProducent() { return $this->producent; } /** * Set category * * @param \AppBundle\Entity\HardwareCategory $category * @return Hardware */ public function setCategory(\AppBundle\Entity\HardwareCategory $category) { $this->category = $category; return $this; } /** * Get category * * @return \AppBundle\Entity\HardwareCategory */ public function getCategory() { return $this->category; } /** * Set model * * @param \AppBundle\Entity\HardwareModel $model * @return Hardware */ public function setModel(\AppBundle\Entity\HardwareModel $model) { $this->model = $model; return $this; } /** * Get model * * @return \AppBundle\Entity\HardwareModel */ public function getModel() { return $this->model; } /** * Set status * * @param \AppBundle\Entity\HardwareStatus $status * @return Hardware */ public function setStatus(\AppBundle\Entity\HardwareStatus $status) { $this->status = $status; return $this; } /** * Get status * * @return \AppBundle\Entity\HardwareStatus */ public function getStatus() { return $this->status; } /** * Add statushistory * * @param \AppBundle\Entity\HardwareStatusHistory $statushistory * @return Hardware */ public function addStatushistory(\AppBundle\Entity\HardwareStatusHistory $statushistory) { $this->statushistory[] = $statushistory; return $this; } /** * Remove statushistory * * @param \AppBundle\Entity\HardwareStatusHistory $statushistory */ public function removeStatushistory(\AppBundle\Entity\HardwareStatusHistory $statushistory) { $this->statushistory->removeElement($statushistory); } /** * Get statushistory * * @return \Doctrine\Common\Collections\Collection */ public function getStatushistory() { return $this->statushistory; } /** * Add magazine * * @param \AppBundle\Entity\MagazineDetails $magazine * @return Hardware */ public function addMagazine(\AppBundle\Entity\MagazineDetails $magazine) { $this->magazine[] = $magazine; return $this; } /** * Remove magazine * * @param \AppBundle\Entity\MagazineDetails $magazine */ public function removeMagazine(\AppBundle\Entity\MagazineDetails $magazine) { $this->magazine->removeElement($magazine); } /** * Get magazine * * @return \Doctrine\Common\Collections\Collection */ public function getMagazine() { return $this->magazine; } /** * Add magazineshift * * @param \AppBundle\Entity\MagazineShiftDetails $magazineshift * @return Hardware */ public function addMagazineshift(\AppBundle\Entity\MagazineShiftDetails $magazineshift) { $this->magazineshift[] = $magazineshift; return $this; } /** * Remove magazineshift * * @param \AppBundle\Entity\MagazineShiftDetails $magazineshift */ public function removeMagazineshift(\AppBundle\Entity\MagazineShiftDetails $magazineshift) { $this->magazineshift->removeElement($magazineshift); } /** * Get magazineshift * * @return \Doctrine\Common\Collections\Collection */ public function getMagazineshift() { return $this->magazineshift; } /** * Add utilize * * @param \AppBundle\Entity\MagazineUtilizeDetails $utilize * @return Hardware */ public function addUtilize(\AppBundle\Entity\MagazineUtilizeDetails $utilize) { $this->utilize[] = $utilize; return $this; } /** * Remove utilize * * @param \AppBundle\Entity\MagazineUtilizeDetails $utilize */ public function removeUtilize(\AppBundle\Entity\MagazineUtilizeDetails $utilize) { $this->utilize->removeElement($utilize); } /** * Get utilize * * @return \Doctrine\Common\Collections\Collection */ public function getUtilize() { return $this->utilize; } /** * Add stocktakingdetails * * @param \AppBundle\Entity\MagazineStockTakingDetails $stocktakingdetails * @return Hardware */ public function addStocktakingdetail(\AppBundle\Entity\MagazineStockTakingDetails $stocktakingdetails) { $this->stocktakingdetails[] = $stocktakingdetails; $stocktakingdetails->setHardware($this); return $this; } /** * Remove stocktakingdetails * * @param \AppBundle\Entity\MagazineStockTakingDetails $stocktakingdetails */ public function removeStocktakingdetail(\AppBundle\Entity\MagazineStockTakingDetails $stocktakingdetails) { $this->stocktakingdetails->removeElement($stocktakingdetails); } /** * Get stocktakingdetails * * @return \Doctrine\Common\Collections\Collection */ public function getStocktakingdetails() { return $this->stocktakingdetails; } }
第一表格类
<?php namespace AppBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class StockTakingFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('stockingnote','textarea',array( 'label' => false, 'attr' => array( 'class' => 'gui-textarea', 'placeholder' => 'Uwagi', 'data-text' => 'Uwagi' ), 'required' => false )) ->add('details','collection',array( 'type' => new StockTakingDetailFormType(), 'allow_add' => true, 'by_reference' => false )) ; } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'AppBundle\Entity\MagazineStockTaking', 'attr' => array( 'id' => 'form_stoking' ) )); } public function getName() { return 'stocktaking'; } }
第二表格类
<?php namespace AppBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class StockTakingDetailFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('count','number',array( 'label' => false, 'data' => '1', 'required' => false )) ->add('hardware','collection',array( 'type' => new HardwareFormType(), 'allow_add' => true, 'by_reference' => false )) ; } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'AppBundle\Entity\MagazineStockTakingDetails' )); } public function getName() { return 'stocktakingtetail'; } }
第三表格类
namespace AppBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class HardwareFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('sn','text',array( 'label' => false, 'attr' => array( 'class' => 'gui-input', 'placeholder' => 'Numer Seryjny Urządzenia' ), 'required' => true )) ->add('gwarantydate','number',array( 'label' => false, 'attr' => array( 'class' => 'gui-input', 'placeholder' => 'Ilość Gwarancji (miesięcy)' ), 'required' => false )) ->add('isreturned','checkbox',array( 'label' => 'Sprzęt Rotacyjny', 'label_attr' => array( 'class' => 'option-primary' ), 'required' => true )) ->add('note','textarea' ,array( 'label' => false, 'attr' => array( 'class' => 'gui-textarea', 'placeholder' => 'Opis', 'data-text' => 'Opis' ), 'required' => false )) ->add('producent','entity',array( 'class' => 'AppBundle\Entity\HardwareProducent', 'property' => 'name', 'label' => false, 'attr' => array( 'class' => 'select', 'placeholder' => 'Producent' ), 'required' => true )) ->add('category','entity',array( 'class' => 'AppBundle\Entity\HardwareCategory', 'property' => 'name', 'label' => false, 'attr' => array( 'class' => 'select', 'placeholder' => 'Kategoria' ), 'required' => true )) ->add('model','entity',array( 'class' => 'AppBundle\Entity\HardwareModel', 'property' => 'name', 'label' => false, 'attr' => array( 'class' => 'select', 'placeholder' => 'Model' ), 'required' => true )) ->add('status','entity',array( 'class' => 'AppBundle\Entity\HardwareStatus', 'property' => 'name', 'label' => false, 'attr' => array( 'class' => 'select', 'placeholder' => 'Status' ), 'required' => true )) ; } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'AppBundle\Entity\Hardware' )); } public function getName() { return 'hardware'; } }
Hi i have problem with form embeded. I have 3 class with relation OneToMany
StockTaking OneToMany StockTakingDetail ManyToOne Hardware
Wheh i submit the form i get error. I dont know where I made a mistake.
Error:
Catchable Fatal Error: Argument 1 passed to AppBundle\Entity\MagazineStockTakingDetails::setHardware() must be an instance of AppBundle\Entity\Hardware, array given, called in C:\Projekty\sla\vendor\symfony\symfony\src\Symfony\Component\PropertyAccess\PropertyAccessor.php on line 442 and defined
Below i past code my class and form. Please help me find mistake.
namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Class MagazineStockTaking * @package AppBundle\Entity * @ORM\Entity() * @ORM\Table(name="sla_stocktaking") */ class MagazineStockTaking { /** * @ORM\Id * @ORM\Column(name="stockTakingId", type="integer", nullable=false) * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(name="stockinNumber", type="string", length=20, nullable=false) */ protected $stockingnumber; /** * @ORM\Column(name="stockinDate", type="datetime", nullable=false) */ protected $stockingdate; /** * @ORM\Column(name="stockingNote", type="string", length=1000, nullable=false) */ protected $stockingnote; //////////////////////////////////////////////// // RELACJE //////////////////////////////////////////////// /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Magazine", inversedBy="stocktaking") * @ORM\JoinColumn(name="magazine_id", referencedColumnName="magazineId", nullable=false) */ protected $magazine; /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="stocktaking") * @ORM\JoinColumn(name="user_id", referencedColumnName="userId", nullable=false) */ protected $user; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\MagazineStockTakingDetails", mappedBy="stocktaking", cascade={"persist"}) */ protected $details; //////////////////////////////////////////////// // GET SET //////////////////////////////////////////////// /** * Constructor */ public function __construct() { $this->details = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set stockingnumber * * @param string $stockingnumber * @return MagazineStockTaking */ public function setStockingnumber($stockingnumber) { $this->stockingnumber = $stockingnumber; return $this; } /** * Get stockingnumber * * @return string */ public function getStockingnumber() { return $this->stockingnumber; } /** * Set stockingdate * * @param \DateTime $stockingdate * @return MagazineStockTaking */ public function setStockingdate($stockingdate) { $this->stockingdate = $stockingdate; return $this; } /** * Get stockingdate * * @return \DateTime */ public function getStockingdate() { return $this->stockingdate; } /** * Set stockingnote * * @param string $stockingnote * @return MagazineStockTaking */ public function setStockingnote($stockingnote) { $this->stockingnote = $stockingnote; return $this; } /** * Get stockingnote * * @return string */ public function getStockingnote() { return $this->stockingnote; } /** * Set magazine * * @param \AppBundle\Entity\Magazine $magazine * @return MagazineStockTaking */ public function setMagazine(\AppBundle\Entity\Magazine $magazine) { $this->magazine = $magazine; return $this; } /** * Get magazine * * @return \AppBundle\Entity\Magazine */ public function getMagazine() { return $this->magazine; } /** * Set user * * @param \AppBundle\Entity\User $user * @return MagazineStockTaking */ public function setUser(\AppBundle\Entity\User $user) { $this->user = $user; return $this; } /** * Get user * * @return \AppBundle\Entity\User */ public function getUser() { return $this->user; } /** * Add details * * @param \AppBundle\Entity\MagazineStockTakingDetails $details * @return MagazineStockTaking */ public function addDetail(\AppBundle\Entity\MagazineStockTakingDetails $details) { $this->details[] = $details; return $this; } /** * Remove details * * @param \AppBundle\Entity\MagazineStockTakingDetails $details */ public function removeDetail(\AppBundle\Entity\MagazineStockTakingDetails $details) { $this->details->removeElement($details); } /** * Get details * * @return \Doctrine\Common\Collections\Collection */ public function getDetails() { return $this->details; } }
Second Class
<?php namespace AppBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; /** * Class MagazineStockTakingDetails * @package AppBundle\Entity * @ORM\Entity() * @ORM\Table(name="sla_stocktakingdetails") */ class MagazineStockTakingDetails { /** * @ORM\Id() * @ORM\Column(name="stackTakingDetailsId", type="integer", nullable=false) * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(name="hardwareCount", type="integer", nullable=false) */ protected $count = 1; ///////////////////////////////////////////// // RELACJE ///////////////////////////////////////////// /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\MagazineStockTaking", inversedBy="details") * @ORM\JoinColumn(name="stacktaking_id", referencedColumnName="stockTakingId", nullable=false) */ protected $stocktaking; /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Hardware", inversedBy="stocktakingdetails",cascade={"persist"}) * @ORM\JoinColumn(name="hardware_id", referencedColumnName="hardwareId", nullable=false) */ protected $hardware; ///////////////////////////////////////////// // GET SET ///////////////////////////////////////////// /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set count * * @param integer $count * @return MagazineStockTakingDetails */ public function setCount($count) { $this->count = $count; return $this; } /** * Get count * * @return integer */ public function getCount() { return $this->count; } /** * Set stocktaking * * @param \AppBundle\Entity\MagazineStockTaking $stocktaking * @return MagazineStockTakingDetails */ public function setStocktaking(\AppBundle\Entity\MagazineStockTaking $stocktaking) { $this->stocktaking = $stocktaking; return $this; } /** * Get stocktaking * * @return \AppBundle\Entity\MagazineStockTaking */ public function getStocktaking() { return $this->stocktaking; } /** * Set hardware * * @param \AppBundle\Entity\Hardware $hardware * @return MagazineStockTakingDetails */ public function setHardware(\AppBundle\Entity\Hardware $hardware) { $this->hardware = $hardware; return $this; } /** * Get hardware * * @return \AppBundle\Entity\Hardware */ public function getHardware() { return $this->hardware; } }
Third Class
<?php namespace AppBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation as JMS; use JMS\Serializer\Annotation\Groups; /** * Class Hardware * @package AppBundle\Entity * @ORM\Entity(repositoryClass="HardwareRepository", ) * @ORM\Table(name="sla_hardwares") * @JMS\ExclusionPolicy("all") */ class Hardware { /** * @ORM\Id() * @ORM\Column(name="hardwareId", type="integer", nullable=false) * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(name="hardwareSn", type="string", length=200, nullable=true) */ protected $sn; /** * @ORM\Column(name="hardwareGwarantyDate", type="datetime", nullable=true) */ protected $gwarantydate; /** * @ORM\Column(name="hardwareNote", type="string", length=750, nullable=true) */ protected $note; /** * @ORM\Column(name="hardwareIsReturned", type="boolean", nullable=false) */ protected $isreturned = false; //////////////////////////////////////// //// RELACJE //////////////////////////////////////// /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\HardwareProducent", inversedBy="hardware") * @ORM\JoinColumn(name="producent_id", referencedColumnName="producentId", nullable=false) */ protected $producent; /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\HardwareCategory", inversedBy="hardware") * @ORM\JoinColumn(name="category_id", referencedColumnName="hardwareCategoryId", nullable=false) */ protected $category; /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\HardwareModel", inversedBy="hardware") * @ORM\JoinColumn(name="model_id", referencedColumnName="hardwareModelId", nullable=false) */ protected $model; /** * @ORM\ManyToOne(targetEntity="AppBundle\Entity\HardwareStatus", inversedBy="hardware") * @ORM\JoinColumn(name="status_id", referencedColumnName="statusId", nullable=false) */ protected $status; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\HardwareStatusHistory", mappedBy="hardware") */ protected $statushistory; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\MagazineDetails", mappedBy="hardware") */ protected $magazine; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\MagazineShiftDetails", mappedBy="hardware") */ protected $magazineshift; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\MagazineUtilizeDetails", mappedBy="hardware") */ protected $utilize; /** * @ORM\OneToMany(targetEntity="AppBundle\Entity\MagazineStockTakingDetails", mappedBy="hardware", cascade={"persist"}) */ protected $stocktakingdetails; //////////////////////////////////////// //// GET SET //////////////////////////////////////// /** * Constructor */ public function __construct() { $this->statushistory = new \Doctrine\Common\Collections\ArrayCollection(); $this->magazine = new \Doctrine\Common\Collections\ArrayCollection(); $this->magazineshift = new \Doctrine\Common\Collections\ArrayCollection(); $this->utilize = new \Doctrine\Common\Collections\ArrayCollection(); $this->stocktakingdetails = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set sn * * @param string $sn * @return Hardware */ public function setSn($sn) { $this->sn = $sn; return $this; } /** * Get sn * * @return string */ public function getSn() { return $this->sn; } /** * Set gwarantydate * * @param \DateTime $gwarantydate * @return Hardware */ public function setGwarantydate($gwarantydate) { $this->gwarantydate = $gwarantydate; return $this; } /** * Get gwarantydate * * @return \DateTime */ public function getGwarantydate() { return $this->gwarantydate; } /** * Set note * * @param string $note * @return Hardware */ public function setNote($note) { $this->note = $note; return $this; } /** * Get note * * @return string */ public function getNote() { return $this->note; } /** * Set isreturned * * @param boolean $isreturned * @return Hardware */ public function setIsreturned($isreturned) { $this->isreturned = $isreturned; return $this; } /** * Get isreturned * * @return boolean */ public function getIsreturned() { return $this->isreturned; } /** * Set producent * * @param \AppBundle\Entity\HardwareProducent $producent * @return Hardware */ public function setProducent(\AppBundle\Entity\HardwareProducent $producent) { $this->producent = $producent; return $this; } /** * Get producent * * @return \AppBundle\Entity\HardwareProducent */ public function getProducent() { return $this->producent; } /** * Set category * * @param \AppBundle\Entity\HardwareCategory $category * @return Hardware */ public function setCategory(\AppBundle\Entity\HardwareCategory $category) { $this->category = $category; return $this; } /** * Get category * * @return \AppBundle\Entity\HardwareCategory */ public function getCategory() { return $this->category; } /** * Set model * * @param \AppBundle\Entity\HardwareModel $model * @return Hardware */ public function setModel(\AppBundle\Entity\HardwareModel $model) { $this->model = $model; return $this; } /** * Get model * * @return \AppBundle\Entity\HardwareModel */ public function getModel() { return $this->model; } /** * Set status * * @param \AppBundle\Entity\HardwareStatus $status * @return Hardware */ public function setStatus(\AppBundle\Entity\HardwareStatus $status) { $this->status = $status; return $this; } /** * Get status * * @return \AppBundle\Entity\HardwareStatus */ public function getStatus() { return $this->status; } /** * Add statushistory * * @param \AppBundle\Entity\HardwareStatusHistory $statushistory * @return Hardware */ public function addStatushistory(\AppBundle\Entity\HardwareStatusHistory $statushistory) { $this->statushistory[] = $statushistory; return $this; } /** * Remove statushistory * * @param \AppBundle\Entity\HardwareStatusHistory $statushistory */ public function removeStatushistory(\AppBundle\Entity\HardwareStatusHistory $statushistory) { $this->statushistory->removeElement($statushistory); } /** * Get statushistory * * @return \Doctrine\Common\Collections\Collection */ public function getStatushistory() { return $this->statushistory; } /** * Add magazine * * @param \AppBundle\Entity\MagazineDetails $magazine * @return Hardware */ public function addMagazine(\AppBundle\Entity\MagazineDetails $magazine) { $this->magazine[] = $magazine; return $this; } /** * Remove magazine * * @param \AppBundle\Entity\MagazineDetails $magazine */ public function removeMagazine(\AppBundle\Entity\MagazineDetails $magazine) { $this->magazine->removeElement($magazine); } /** * Get magazine * * @return \Doctrine\Common\Collections\Collection */ public function getMagazine() { return $this->magazine; } /** * Add magazineshift * * @param \AppBundle\Entity\MagazineShiftDetails $magazineshift * @return Hardware */ public function addMagazineshift(\AppBundle\Entity\MagazineShiftDetails $magazineshift) { $this->magazineshift[] = $magazineshift; return $this; } /** * Remove magazineshift * * @param \AppBundle\Entity\MagazineShiftDetails $magazineshift */ public function removeMagazineshift(\AppBundle\Entity\MagazineShiftDetails $magazineshift) { $this->magazineshift->removeElement($magazineshift); } /** * Get magazineshift * * @return \Doctrine\Common\Collections\Collection */ public function getMagazineshift() { return $this->magazineshift; } /** * Add utilize * * @param \AppBundle\Entity\MagazineUtilizeDetails $utilize * @return Hardware */ public function addUtilize(\AppBundle\Entity\MagazineUtilizeDetails $utilize) { $this->utilize[] = $utilize; return $this; } /** * Remove utilize * * @param \AppBundle\Entity\MagazineUtilizeDetails $utilize */ public function removeUtilize(\AppBundle\Entity\MagazineUtilizeDetails $utilize) { $this->utilize->removeElement($utilize); } /** * Get utilize * * @return \Doctrine\Common\Collections\Collection */ public function getUtilize() { return $this->utilize; } /** * Add stocktakingdetails * * @param \AppBundle\Entity\MagazineStockTakingDetails $stocktakingdetails * @return Hardware */ public function addStocktakingdetail(\AppBundle\Entity\MagazineStockTakingDetails $stocktakingdetails) { $this->stocktakingdetails[] = $stocktakingdetails; $stocktakingdetails->setHardware($this); return $this; } /** * Remove stocktakingdetails * * @param \AppBundle\Entity\MagazineStockTakingDetails $stocktakingdetails */ public function removeStocktakingdetail(\AppBundle\Entity\MagazineStockTakingDetails $stocktakingdetails) { $this->stocktakingdetails->removeElement($stocktakingdetails); } /** * Get stocktakingdetails * * @return \Doctrine\Common\Collections\Collection */ public function getStocktakingdetails() { return $this->stocktakingdetails; } }
First Form Class
<?php namespace AppBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class StockTakingFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('stockingnote','textarea',array( 'label' => false, 'attr' => array( 'class' => 'gui-textarea', 'placeholder' => 'Uwagi', 'data-text' => 'Uwagi' ), 'required' => false )) ->add('details','collection',array( 'type' => new StockTakingDetailFormType(), 'allow_add' => true, 'by_reference' => false )) ; } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'AppBundle\Entity\MagazineStockTaking', 'attr' => array( 'id' => 'form_stoking' ) )); } public function getName() { return 'stocktaking'; } }
Second Form Class
<?php namespace AppBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class StockTakingDetailFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('count','number',array( 'label' => false, 'data' => '1', 'required' => false )) ->add('hardware','collection',array( 'type' => new HardwareFormType(), 'allow_add' => true, 'by_reference' => false )) ; } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'AppBundle\Entity\MagazineStockTakingDetails' )); } public function getName() { return 'stocktakingtetail'; } }
Third Form Class
namespace AppBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class HardwareFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('sn','text',array( 'label' => false, 'attr' => array( 'class' => 'gui-input', 'placeholder' => 'Numer Seryjny Urządzenia' ), 'required' => true )) ->add('gwarantydate','number',array( 'label' => false, 'attr' => array( 'class' => 'gui-input', 'placeholder' => 'Ilość Gwarancji (miesięcy)' ), 'required' => false )) ->add('isreturned','checkbox',array( 'label' => 'Sprzęt Rotacyjny', 'label_attr' => array( 'class' => 'option-primary' ), 'required' => true )) ->add('note','textarea' ,array( 'label' => false, 'attr' => array( 'class' => 'gui-textarea', 'placeholder' => 'Opis', 'data-text' => 'Opis' ), 'required' => false )) ->add('producent','entity',array( 'class' => 'AppBundle\Entity\HardwareProducent', 'property' => 'name', 'label' => false, 'attr' => array( 'class' => 'select', 'placeholder' => 'Producent' ), 'required' => true )) ->add('category','entity',array( 'class' => 'AppBundle\Entity\HardwareCategory', 'property' => 'name', 'label' => false, 'attr' => array( 'class' => 'select', 'placeholder' => 'Kategoria' ), 'required' => true )) ->add('model','entity',array( 'class' => 'AppBundle\Entity\HardwareModel', 'property' => 'name', 'label' => false, 'attr' => array( 'class' => 'select', 'placeholder' => 'Model' ), 'required' => true )) ->add('status','entity',array( 'class' => 'AppBundle\Entity\HardwareStatus', 'property' => 'name', 'label' => false, 'attr' => array( 'class' => 'select', 'placeholder' => 'Status' ), 'required' => true )) ; } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'AppBundle\Entity\Hardware' )); } public function getName() { return 'hardware'; } }
原文:https://stackoverflow.com/questions/34908781
满意答案
你也可以添加一个对数函数。 (取自tagadelic,我的Drupal模块创建标签云http://drupal.org/project/tagadelic ):
db_query('SELECT COUNT(*) AS count, id, name FROM ... ORDER BY count DESC'); $steps = 6; $tags = array(); $min = 1e9; $max = -1e9; while ($tag = db_fetch_object($result)) { $tag->number_of_posts = $tag->count; #sets the amount of items a certain tag has attached to it $tag->count = log($tag->count); $min = min($min, $tag->count); $max = max($max, $tag->count); $tags[$tag->tid] = $tag; } // Note: we need to ensure the range is slightly too large to make sure even // the largest element is rounded down. $range = max(.01, $max - $min) * 1.0001; foreach ($tags as $key => $value) { $tags[$key]->weight = 1 + floor($steps * ($value->count - $min) / $range); }
然后在您的视图或模板中:
foreach ($tags as $tag) { $output .= "<h$tag->weight>$tag->name</h$tag->weight>" }
You will want to add a logarithmic function to it too. (taken from tagadelic, my Drupal module to create tag clouds http://drupal.org/project/tagadelic):
db_query('SELECT COUNT(*) AS count, id, name FROM ... ORDER BY count DESC'); $steps = 6; $tags = array(); $min = 1e9; $max = -1e9; while ($tag = db_fetch_object($result)) { $tag->number_of_posts = $tag->count; #sets the amount of items a certain tag has attached to it $tag->count = log($tag->count); $min = min($min, $tag->count); $max = max($max, $tag->count); $tags[$tag->tid] = $tag; } // Note: we need to ensure the range is slightly too large to make sure even // the largest element is rounded down. $range = max(.01, $max - $min) * 1.0001; foreach ($tags as $key => $value) { $tags[$key]->weight = 1 + floor($steps * ($value->count - $min) / $range); }
Then in your view or template:
foreach ($tags as $tag) { $output .= "<h$tag->weight>$tag->name</h$tag->weight>" }
相关问答
更多为什么使用.h1而不是实际的h1?(Why use .h1 instead of actual h1?)
使用h1至h6进行大小调整从阵列生成标签云的最佳方式是什么?(What's the best way to generate a tag cloud from an array using h1 through h6 for sizing?)
h1 - h6标签是否应该按顺序使用,还是数字是任意的?(Should h1 - h6 tags always be used sequentially, or are the numbers arbitrary?)
在标头(H1)标签中显示数组值(Display Array Value in Header (H1) Tag)
是否有一个jQuery选择器(h1,h2,h3,h4,h5或h6)?(Is there a jQuery selector for header (h1, h2, h3, h4, h5, or h6)?)
如何首先加载H1标签(How do I load a H1 tag first)
如何包装H1标签的内容(How to wrap content of H1 tag)
为什么CSS选择器“h1,h2,h3,h4,h5,h6 + p”不起作用,有什么替代方案?(Why doesn't CSS selector “h1,h2,h3,h4,h5,h6 + p” work, and what is an alternative?)
操纵H1标签(Manipulation H1 Tag)
无法识别附加的h1标签(Appended h1 tag not recognized)
相关文章
更多Symfony2网站开发
Hibernate 异常之:associate a collection with two ...
英语谚语精选(English Proverb Collection)
CLR Via C# 3rd 阅读摘要 -- Chapter 21 – Automatic Memory Management (Garbage Collection)
用好Collection 对solrj入库进行优化
Solr参数(Analysis Collection Common CoreAdmin)
Spark - A Fault-Tolerant Abstraction for In-Memory Cluster Computing
Spring Data: a new perspective of data operations
Drupal Forums instead of phpBB or vBulletin: A casestudy
Become a Master Designer: Rule Three: Contrast, Contrast, Contrast
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!