首页 \ 问答 \ Symfony2嵌入了一系列表单(Symfony2 Embed a Collection of Forms)

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
更新时间:2023-11-10 22:11

最满意答案

你也可以添加一个对数函数。 (取自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 ? 简答: 目标是一起使用两者。 当设计中的排版大小与语义上适当的标题级别不相关时, .h*类的有用性就起作用了。 通过将问题分解为两个,我们可以干净地解决这两个问题。 第一位是元素/标签。 ' '处理语义,可访问性和SEO。 第二位是班级。 ' .h* '负责视觉语义和排版层次。 长答案: 我相信这些课程的起源来自于OOCSS项目: 面向对象的CSS OOCSS的最新版本自从我上次看到以来已经有了一些改变,但这是相关的heading.css文件,从较早的 ...
  • 你也可以添加一个对数函数。 (取自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)) { ...
  • HTML5规范说 4.3.10标题和章节 h1 - h6元素是标题。 切片内容元素中标题内容的第一个元素表示该部分的标题。 等级或更高等级的后续标题开始新的(隐含的)部分,较低等级的标题开始隐含的子部分是前一部分的一部分。 在这两种情况下,元素代表隐含部分的标题。 [...] 章节可能包含任何等级的标题,强烈建议作者使用适当等级的标题作为该部分的嵌套级别。 The HTML5 spec says 4.3.10 Headings and sections The h1–h6 elements are head ...
  • 就在这里。 您可以使用jQuery(":header")选择所有标题 以下是该文档的链接: http : //api.jquery.com/header-selector/ 请注意,由于此选择器是jQuery扩展,而不是CSS规范的一部分,因此使用此选择器的查询无法利用本机DOM querySelectorAll()方法提供的性能提升。 要在使用这些选择器时实现最佳性能,请先使用纯CSS选择器选择一些元素,然后使用.filter() 。 Yes there is. You can select all he ...
  • 问题是你的背景图片和徽标图片(在h1标签中)。 尝试在图像编辑器中优化它们,并将它们保存为Web。 此外,您应该将它们保存为.jpeg ,因为它们不是透明图像,因此您可以从文件大小中节省更多。 稍后编辑:如果您想要透明徽标图像,请将其另存为jpeg for web,然后使用css opacity 。 The problem is your background image and the logo image(in the h1 tag). Try to optimize them in a image e ...
  • 很少,文本溢出文本框。 在这种情况下,可以强制浏览器更改换行。 网页设计师墙 在这里解释: .break-word { word-wrap: break-word; } 更改渲染行为,如下所示: 另外,虽然在当前情况下可能没有帮助,但可以使用CSS 隐藏任何溢出 : style="overflow:hidden;" PS:实际上,我想知道,如果自动换行是问题的根本原因。 Quite seldom, text overflows text-boxes. In such cases, one can f ...
  • 我认为你需要的是以下一组选择器: h1+p, h2+p, h3+p, h4+p, h5+p, h6+p 语法要求您在每个标头标记后添加“+ p”。 在当前选择器中,CSS应用于标头h1-h5和h6 + p。 这看起来可能并不优雅,但它正是您所需要的。 I think that what you need is the following group of selectors: h1+p, h2+p, h3+p, h4+p, h5+p, h6+p The syntax requires that you ...
  • 在h1标签内部取最初的html。 用br标签拆分它。 使用span标记调整已拆分html的第二部分。 使用br标记加入拆分的部分并将它们放回到h1标记中: var html = $("#title").html(); var parts = html.split("
    "); parts[1] = ""+parts[1]+""; $("#title").html(parts.join("
    ")); .preTitle{ c ...
  • Web爬网程序不执行JavaScript,因此不会创建

    标记。 如果您希望此标记对Web爬网程序可见,则需要使用服务器端语言生成它。 Web crawlers don't execute your JavaScript, so the

    tag isn't created. If you want this tag to be visible to web crawlers, you need to generate it with your serverside language.

相关文章

更多

最新问答

更多
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • Java中的不可变类(Immutable class in Java)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • EXCEL VBA 基础教程下载
  • RoR - 邮件中的动态主体(部分)(RoR - Dynamic body (part) in mailer)
  • 无法在Google Script中返回2D数组?(Can not return 2D Array in Google Script?)
  • JAVA环境变量的设置和对path , classpth ,java_home设置作用和目的?
  • mysql 关于分组查询、时间条件查询
  • 如何使用PowerShell匹配运算符(How to use the PowerShell match operator)
  • Effective C ++,第三版:重载const函数(Effective C++, Third edition: Overloading const function)
  • 如何用DELPHI动态建立MYSQL的数据库和表? 请示出源代码。谢谢!
  • 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
  • 使用前端框架带来哪些好处,相对于使用jquery
  • Ruby将字符串($ 100.99)转换为float或BigDecimal(Ruby convert string ($100.99) to float or BigDecimal)
  • 高考完可以去做些什么?注意什么?
  • 如何声明放在main之后的类模板?(How do I declare a class template that is placed after the main?)
  • 如何使用XSLT基于兄弟姐妹对元素进行分组(How to group elements based on their siblings using XSLT)
  • 在wordpress中的所有页面的标志(Logo in all pages in wordpress)
  • R:使用rollapply对列组进行求和的问题(R: Problems using rollapply to sum groups of columns)
  • Allauth不会保存其他字段(Allauth will not save additional fields)
  • python中使用sys模块中sys.exit()好像不能退出?
  • 将Int拆分为3个字节并返回C语言(Splitting an Int to 3 bytes and back in C)
  • 在SD / MMC中启用DDR会导致问题吗?(Enabling DDR in SD/MMC causes problems? CMD 11 gives a response but the voltage switch wont complete)
  • sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
  • 如何将字符串转换为Elixir中的函数(how to convert a string to a function in Elixir)