@ORM \ PrePersist不允许在财产上申报

时间:2017-03-10 18:09:53

标签: php zend-framework2 doctrine

我过去几天一直在学习zend框架。我尝试运行该站点时遇到此错误:

注释@ORM \ PrePersist不允许在属性Post \ Entity \ Post :: $ alterado上声明。您只能在这些代码元素上使用此注释:METHOD。

继承我的Post.php文件:

 <?php

 namespace Post\Entity;

 use Application\Entity\AbstractEntity;
 use Doctrine\ORM\Mapping as ORM;

 /**
 * Post
 *
 * @ORM\Table(name="post")
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks
 * @ORM\Entity(repositoryClass="Post\Entity\PostRepository")
 */
 class Post extends AbstractEntity
 {
 /**
 * @var integer
 * @ORM\Id
 * @ORM\Column(name="id", type="integer", nullable=false)
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="titulo", type="string", length=80, nullable=false)
 */
private $titulo;

/**
 * @var string
 *
 * @ORM\Column(name="descricao", type="string", length=150, nullable=false)
 */
private $descricao;

/**
 * @var string
 *
 * @ORM\Column(name="texto", type="text", nullable=false)
 */
private $texto;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="cadastro", type="datetime", nullable=false)
 */
private $cadastro;

/**
 * @var \DateTime
 * @ORM\PrePersist
 * @ORM\Column(name="alterado", type="datetime", nullable=false)
 */
private $alterado;

/**
 * @var boolean
 * @ORM\PosUpdate
 * @ORM\Column(name="ativo", type="boolean", nullable=false)
 */
private $ativo = '0';

/**
 * @var \Categoria\Entity\Category
 *
 * @ORM\ManyToOne(targetEntity="Categoria\Entity\Category")
 * @ORM\JoinColumn(name="categoria_id", referencedColumnName="id")
 */
private $categoriaId;



/**
 * Set id
 *
 * @param integer $id
 *
 * @return Post
 */
public function setId($id)
{
    $this->id = $id;

    return $this;
}

/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this->id;
}

/**
 * Set titulo
 *
 * @param string $titulo
 *
 * @return Post
 */
public function setTitulo($titulo)
{
    $this->titulo = $titulo;

    return $this;
}

/**
 * Get titulo
 *
 * @return string
 */
public function getTitulo()
{
    return $this->titulo;
}

/**
 * Set descricao
 *
 * @param string $descricao
 *
 * @return Post
 */
public function setDescricao($descricao)
{
    $this->descricao = $descricao;

    return $this;
}

/**
 * Get descricao
 *
 * @return string
 */
public function getDescricao()
{
    return $this->descricao;
}

/**
 * Set texto
 *
 * @param string $texto
 *
 * @return Post
 */
public function setTexto($texto)
{
    $this->texto = $texto;

    return $this;
}

/**
 * Get texto
 *
 * @return string
 */
public function getTexto()
{
    return $this->texto;
}

/**
 * Set cadastro
 *
 * @param \DateTime $cadastro
 *
 * @return Post
 */
public function setCadastro($cadastro)
{
    $this->cadastro = $cadastro;

    return $this;
}

/**
 * Get cadastro
 *
 * @return \DateTime
 */
public function getCadastro()
{
    return $this->cadastro;
}

/**
 * Set alterado
 *
 * @param \DateTime $alterado
 *
 * @return Post
 */
public function setAlterado($alterado)
{
    $this->alterado = $alterado;

    return $this;
}

/**
 * Get alterado
 *
 * @return \DateTime
 */
public function getAlterado()
{
    return $this->alterado;
}

/**
 * Set ativo
 *
 * @param boolean $ativo
 *
 * @return Post
 */
public function setAtivo($ativo)
{
    $this->ativo = $ativo;

    return $this;
}

/**
 * Get ativo
 *
 * @return boolean
 */
public function getAtivo()
{
    return $this->ativo;
}

/**
 * Set categoriaId
 *
 * @param \Categoria\Entity\Category $categoriaId
 *
 * @return Post
 */
public function setCategoriaId(\Categoria\Entity\Category $categoriaId = null)
{
    $this->categoriaId = $categoriaId;

    return $this;
}

/**
 * Get categoriaId
 *
 * @return \Categoria\Entity\Category
 */
public function getCategoriaId()
{
    return $this->categoriaId;
}
}

我错过了文件中的任何“使用”声明吗?

任何帮助都是恭喜的,感谢您的关注:)

1 个答案:

答案 0 :(得分:0)

我修复了它,我应该在方法上调用@ORM \ PrePersist和@ORM \ PosUpdate。 :)