我有一个与我的Symfony2项目相关的小型数据库。我有我的控制器,实体等。
当我尝试使用方法find()时,我总是获得null。
以下是调用find方法的方法:
public function loginsuccessAction()
{
$em = $this->getDoctrine()->getEntityManager();
$user = $em->getRepository('MDPILoginBundle:Users')->find(1);
var_dump($user);
}
我的用户实体类具有所需的getter和setter。我的表用户人数众多。
我错过了什么?新的symfony,我试图第一次这样做,阅读一些教程。
非常感谢。
PS:如果您需要更多详情,请随时问我。
编辑:实体Users.php添加
这是Users.php实体
<?php
namespace MDPI\LoginBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* MDPI\LoginBundle\Entity\Users
*
* @ORM\Table(name="users")
* @ORM\Entity
*/
class Users
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var integer $editorId
*
* @ORM\Column(name="editor_id", type="integer", nullable=true)
*/
private $editorId;
/**
* @var string $email
*
* @ORM\Column(name="email", type="string", length=255, nullable=false)
*/
private $email;
/**
* @var string $password
*
* @ORM\Column(name="password", type="string", length=255, nullable=false)
*/
private $password;
/**
* @var integer $titleId
*
* @ORM\Column(name="title_id", type="integer", nullable=true)
*/
private $titleId;
/**
* @var string $firstname
*
* @ORM\Column(name="firstname", type="string", length=255, nullable=true)
*/
private $firstname;
/**
* @var string $lastname
*
* @ORM\Column(name="lastname", type="string", length=255, nullable=true)
*/
private $lastname;
/**
* @var string $department
*
* @ORM\Column(name="department", type="string", length=255, nullable=true)
*/
private $department;
/**
* @var string $organization
*
* @ORM\Column(name="organization", type="string", length=255, nullable=true)
*/
private $organization;
/**
* @var string $address1
*
* @ORM\Column(name="address1", type="string", length=255, nullable=true)
*/
private $address1;
/**
* @var string $address2
*
* @ORM\Column(name="address2", type="string", length=255, nullable=true)
*/
private $address2;
/**
* @var string $city
*
* @ORM\Column(name="city", type="string", length=50, nullable=true)
*/
private $city;
/**
* @var string $state
*
* @ORM\Column(name="state", type="string", length=50, nullable=true)
*/
private $state;
/**
* @var string $zipcode
*
* @ORM\Column(name="zipcode", type="string", length=50, nullable=true)
*/
private $zipcode;
/**
* @var integer $countryId
*
* @ORM\Column(name="country_id", type="integer", nullable=true)
*/
private $countryId;
/**
* @var string $telephone
*
* @ORM\Column(name="telephone", type="string", length=25, nullable=true)
*/
private $telephone;
/**
* @var string $fax
*
* @ORM\Column(name="fax", type="string", length=25, nullable=true)
*/
private $fax;
/**
* @var integer $workplaceId
*
* @ORM\Column(name="workplace_id", type="integer", nullable=true)
*/
private $workplaceId;
/**
* @var integer $jobtypeId
*
* @ORM\Column(name="jobtype_id", type="integer", nullable=true)
*/
private $jobtypeId;
/**
* @var string $researchKeywords
*
* @ORM\Column(name="research_keywords", type="string", length=255, nullable=true)
*/
private $researchKeywords;
/**
* @var string $ip
*
* @ORM\Column(name="ip", type="string", length=15, nullable=true)
*/
private $ip;
/**
* @var boolean $status
*
* @ORM\Column(name="status", type="boolean", nullable=false)
*/
private $status;
/**
* @var boolean $active
*
* @ORM\Column(name="active", type="boolean", nullable=false)
*/
private $active;
/**
* @var bigint $dateRegistered
*
* @ORM\Column(name="date_registered", type="bigint", nullable=false)
*/
private $dateRegistered;
/**
* @var string $alertFrequency
*
* @ORM\Column(name="alert_frequency", type="string", length=10, nullable=true)
*/
private $alertFrequency;
/**
* @var datetime $alertLastSuccess
*
* @ORM\Column(name="alert_last_success", type="datetime", nullable=false)
*/
private $alertLastSuccess;
/**
* @var text $signature
*
* @ORM\Column(name="signature", type="text", nullable=true)
*/
private $signature;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set editorId
*
* @param integer $editorId
*/
public function setEditorId($editorId)
{
$this->editorId = $editorId;
}
/**
* Get editorId
*
* @return integer
*/
public function getEditorId()
{
return $this->editorId;
}
/**
* Set email
*
* @param string $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set password
*
* @param string $password
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set titleId
*
* @param integer $titleId
*/
public function setTitleId($titleId)
{
$this->titleId = $titleId;
}
/**
* Get titleId
*
* @return integer
*/
public function getTitleId()
{
return $this->titleId;
}
/**
* Set firstname
*
* @param string $firstname
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
}
/**
* Get firstname
*
* @return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set lastname
*
* @param string $lastname
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
}
/**
* Get lastname
*
* @return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set department
*
* @param string $department
*/
public function setDepartment($department)
{
$this->department = $department;
}
/**
* Get department
*
* @return string
*/
public function getDepartment()
{
return $this->department;
}
/**
* Set organization
*
* @param string $organization
*/
public function setOrganization($organization)
{
$this->organization = $organization;
}
/**
* Get organization
*
* @return string
*/
public function getOrganization()
{
return $this->organization;
}
/**
* Set address1
*
* @param string $address1
*/
public function setAddress1($address1)
{
$this->address1 = $address1;
}
/**
* Get address1
*
* @return string
*/
public function getAddress1()
{
return $this->address1;
}
/**
* Set address2
*
* @param string $address2
*/
public function setAddress2($address2)
{
$this->address2 = $address2;
}
/**
* Get address2
*
* @return string
*/
public function getAddress2()
{
return $this->address2;
}
/**
* Set city
*
* @param string $city
*/
public function setCity($city)
{
$this->city = $city;
}
/**
* Get city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set state
*
* @param string $state
*/
public function setState($state)
{
$this->state = $state;
}
/**
* Get state
*
* @return string
*/
public function getState()
{
return $this->state;
}
/**
* Set zipcode
*
* @param string $zipcode
*/
public function setZipcode($zipcode)
{
$this->zipcode = $zipcode;
}
/**
* Get zipcode
*
* @return string
*/
public function getZipcode()
{
return $this->zipcode;
}
/**
* Set countryId
*
* @param integer $countryId
*/
public function setCountryId($countryId)
{
$this->countryId = $countryId;
}
/**
* Get countryId
*
* @return integer
*/
public function getCountryId()
{
return $this->countryId;
}
/**
* Set telephone
*
* @param string $telephone
*/
public function setTelephone($telephone)
{
$this->telephone = $telephone;
}
/**
* Get telephone
*
* @return string
*/
public function getTelephone()
{
return $this->telephone;
}
/**
* Set fax
*
* @param string $fax
*/
public function setFax($fax)
{
$this->fax = $fax;
}
/**
* Get fax
*
* @return string
*/
public function getFax()
{
return $this->fax;
}
/**
* Set workplaceId
*
* @param integer $workplaceId
*/
public function setWorkplaceId($workplaceId)
{
$this->workplaceId = $workplaceId;
}
/**
* Get workplaceId
*
* @return integer
*/
public function getWorkplaceId()
{
return $this->workplaceId;
}
/**
* Set jobtypeId
*
* @param integer $jobtypeId
*/
public function setJobtypeId($jobtypeId)
{
$this->jobtypeId = $jobtypeId;
}
/**
* Get jobtypeId
*
* @return integer
*/
public function getJobtypeId()
{
return $this->jobtypeId;
}
/**
* Set researchKeywords
*
* @param string $researchKeywords
*/
public function setResearchKeywords($researchKeywords)
{
$this->researchKeywords = $researchKeywords;
}
/**
* Get researchKeywords
*
* @return string
*/
public function getResearchKeywords()
{
return $this->researchKeywords;
}
/**
* Set ip
*
* @param string $ip
*/
public function setIp($ip)
{
$this->ip = $ip;
}
/**
* Get ip
*
* @return string
*/
public function getIp()
{
return $this->ip;
}
/**
* Set status
*
* @param boolean $status
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
* Get status
*
* @return boolean
*/
public function getStatus()
{
return $this->status;
}
/**
* Set active
*
* @param boolean $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* Get active
*
* @return boolean
*/
public function getActive()
{
return $this->active;
}
/**
* Set dateRegistered
*
* @param bigint $dateRegistered
*/
public function setDateRegistered($dateRegistered)
{
$this->dateRegistered = $dateRegistered;
}
/**
* Get dateRegistered
*
* @return bigint
*/
public function getDateRegistered()
{
return $this->dateRegistered;
}
/**
* Set alertFrequency
*
* @param string $alertFrequency
*/
public function setAlertFrequency($alertFrequency)
{
$this->alertFrequency = $alertFrequency;
}
/**
* Get alertFrequency
*
* @return string
*/
public function getAlertFrequency()
{
return $this->alertFrequency;
}
/**
* Set alertLastSuccess
*
* @param datetime $alertLastSuccess
*/
public function setAlertLastSuccess($alertLastSuccess)
{
$this->alertLastSuccess = $alertLastSuccess;
}
/**
* Get alertLastSuccess
*
* @return datetime
*/
public function getAlertLastSuccess()
{
return $this->alertLastSuccess;
}
/**
* Set signature
*
* @param text $signature
*/
public function setSignature($signature)
{
$this->signature = $signature;
}
/**
* Get signature
*
* @return text
*/
public function getSignature()
{
return $this->signature;
}
}
答案 0 :(得分:2)
确保您在find方法中使用的值与实体中定义的主键(@ID)相同。