0
我試圖在Smyony2上使用d:f:l時出現這個錯誤,對於Servicio和Usuario我得到了同樣的錯誤,所以我發佈了一個例子,如果你幫我,另一個也會被修復。Symfony2燈具
[ErrorException]
Catchable Fatal Error: Argument 1 passed to PGE\BitacoraBundle\Entity\Tarea::setServicio() must be an instance of PGE\BitacoraBundle\Entity\Servicio, integer given, called in D:\Zend\Apache2\htdocs\PGE\src\PGE\BitacoraBu
ndle\DataFixtures\ORM\Tareas.php on line 20 and defined in D:\Zend\Apache2\htdocs\PGE\src\PGE\BitacoraBundle\Entity\Tarea.php line 281
這是代碼:
Tareas.php
<?php
namespace PGE\BitacoraBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use PGE\BitacoraBundle\Entity\Tarea;
class Tareas extends AbstractFixture implements OrderedFixtureInterface
{
public function getOrder()
{
return 3;
}
public function load(ObjectManager $manager)
{
for ($i = 1; $i < 5; $i++) {
$entidad = new Tarea();
$entidad->setServicio($i);
$entidad->setFechaInicio(new \DateTime());
$entidad->setFechaFinal(new \DateTime());
$entidad->setDescripcion('Descripcion aqui');
$entidad->setEstado('Pendiente');
$entidad->setPrioridad('P1');
$entidad->setResumen('Hola soy un resumen');
$entidad->setSolicitante('x068753');
$entidad->setUsuario($i);
}
$manager->flush();
}
}
Usuario.php
<?php
namespace PGE\BitacoraBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="bitacora_usuario")
*/
class Usuario
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private $id;
/** @ORM\Column(type="string", length=255) */
private $nombre;
/** @ORM\Column(type="string", length=255) */
private $apellidos;
/** @ORM\Column(type="string", length=255) */
private $prbes;
public function __toString()
{
return $this->getNombre().' '.$this->getApellidos();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set nombre
*
* @param string $nombre
* @return Usuario
*/
public function setNombre($nombre)
{
$this->nombre = $nombre;
return $this;
}
/**
* Get nombre
*
* @return string
*/
public function getNombre()
{
return $this->nombre;
}
/**
* Set apellidos
*
* @param string $apellidos
* @return Usuario
*/
public function setApellidos($apellidos)
{
$this->apellidos = $apellidos;
return $this;
}
/**
* Get apellidos
*
* @return string
*/
public function getApellidos()
{
return $this->apellidos;
}
/**
* Set prbes
*
* @param string $prbes
* @return Usuario
*/
public function setPrbes($prbes)
{
$this->prbes = $prbes;
return $this;
}
/**
* Get prbes
*
* @return string
*/
public function getPrbes()
{
return $this->prbes;
}
}
編輯:我使用的Symfony的2.1.x
該消息是不言自明的,你應該通過一個Servicio對象,但你傳遞一個整數,而不是...你期望什麼? – greg0ire
此外,你不告訴經理堅持任何事情,所以什麼都不會發生。確保爲每次迭代添加'$ manager-> persist($ entidad);'。 – RobMasters
我忘了在這裏寫下堅持的方法,但我正在使用它。我想要的是在setServicio上設置一個整數,因爲它連接到另一個我有Servicio名稱的表......我之前可以創建,但上個月我沒有使用過symfony,所以我忘記了很多... –