Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php @不允许在属性上声明ORM\PrePersist_Php_Zend Framework2_Doctrine - Fatal编程技术网

Php @不允许在属性上声明ORM\PrePersist

Php @不允许在属性上声明ORM\PrePersist,php,zend-framework2,doctrine,Php,Zend Framework2,Doctrine,过去几天我一直在学习zend框架。我在尝试运行站点时遇到此错误: 不允许在属性Post\Entity\Post::$alterado上声明注释@ORM\PrePersist。只能在以下代码元素上使用此注释:方法 这是我的Post.php文件: <?php namespace Post\Entity; use Application\Entity\AbstractEntity; use Doctrine\ORM\Mapping as ORM; /** * Post *

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

不允许在属性Post\Entity\Post::$alterado上声明注释@ORM\PrePersist。只能在以下代码元素上使用此注释:方法

这是我的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;
}
}

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