简体   繁体   中英

Symfony2: Query the database with Doctrine

I have a small database connected with my Symfony2 project. I have my controller, the entity etc.

When I try to use the method find(), I am allways obtaining a null.

Here is how the find method is called:

 public function loginsuccessAction()
{

$em = $this->getDoctrine()->getEntityManager();
$user = $em->getRepository('MDPILoginBundle:Users')->find(1);

var_dump($user);
}

My Users entity class has the needed getters and setters. My table Users is well populated.

What am I missing ? New with symfony, I am trying to do it for the first time, reading some tutorials.

Thank you very much.

PS: If you need more details, please feel free to ask me.

EDIT: Entity Users.php added

Here is the Users.php entity

<?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;
}

}

确保在find方法中使用的值与实体中定义的主键(@ID)相同。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM