用户实体:
<?php
namespace AppEntity;
use AppEntity;
use DoctrineORMMapping;
/**
* @Entity
* @Table(name="users", options={"collate":"utf8_general_ci", "charset":"utf8", "engine":"MyISAM"})
*/
class Users extends Entity {
/**
* @Column(type="string", length=50)
* @var string
*/
protected $email;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $encrypted_password;
/**
* @Column(type="string", length=10)
* @var string
*/
protected $salt;
/**
* @Column(type="smallint", options={"default":"0","comment":"0 : Doctor, 1 : Assistant, 2 : Student"}))
* @var smallint
*/
protected $type;
/**
* @Column(type="string", length=150)
* @var string
*/
protected $sef_link;
/**
* @return string
*/
public function getEmail() {
return $this->email;
}
/**
* @param string $email
*/
public function setEmail($email) {
$this->email = $email;
}
/**
* @return string
*/
public function getEncryptedPassword() {
return $this->encrypted_password;
}
/**
* @param string $encrypted_password
*/
public function setEncryptedPassword($encrypted_password) {
$this->encrypted_password = $encrypted_password;
}
/**
* @return string
*/
public function getSalt() {
return $this->salt;
}
/**
* @param string $salt
*/
public function setSalt($salt) {
$this->salt = $salt;
}
/**
* @return integer
*/
public function getType() {
return $this->type;
}
/**
* @param integer $type
*/
public function setType($type) {
$this->type = $type;
}
/**
* @return string
*/
public function getSefLink() {
return $this->sef_link;
}
/**
* @param string $sef_link
*/
public function setSefLink($sef_link) {
$this->sef_link = $sef_link;
}
}
用户信息实体:
<?php
namespace AppEntity;
use AppEntity;
use DoctrineORMMapping;
/**
* @Entity
* @Table(name="user_information", options={"collate":"utf8_general_ci", "charset":"utf8", "engine":"MyISAM"})
*/
class UserInformation extends Entity {
/**
* @Column(type="integer", unique=true)
* @var integer
*/
protected $uid;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $title;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $name;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $surname;
/**
* @Column(type="date", nullable=true)
* @var date
*/
protected $born;
/**
* @Column(type="text", length=65532)
* @var text
*/
protected $address;
/**
* @Column(type="string", length=100)
* @var string
*/
protected $cv_path;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $facebook_link;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $twitter_link;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $instagram_link;
/**
* @Column(type="string", length=50)
* @var string
*/
protected $linkedin_link;
/**
* @Column(type="string", length=100)
* @var string
*/
protected $img_path;
/**
* @Column(type="date", nullable=true)
* @var date
*/
protected $university_graduated_at;
/**
* @Column(type="date", nullable=true)
* @var date
*/
protected $md_graduated_at;
/**
* @Column(type="date", nullable=true)
* @var date
*/
protected $associate_professor_graduated_at;
/**
* @return int
*/
public function getUid() {
return $this->uid;
}
/**
* @param int $uid
*/
public function setUid($uid) {
$this->uid = $uid;
}
/**
* @return string
*/
public function getTitle() {
return $this->title;
}
/**
* @param string $title
*/
public function setTitle($title) {
$this->title = $title;
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @param string $name
*/
public function setName($name) {
$this->name = $name;
}
/**
* @return string
*/
public function getSurname() {
return $this->surname;
}
/**
* @param string $surname
*/
public function setSurname($surname) {
$this->surname = $surname;
}
/**
* @return date
*/
public function getBorn() {
return $this->born;
}
/**
* @param date $born
*/
public function setBorn($born) {
$this->born = $born;
}
/**
* @return text
*/
public function getAddress() {
return $this->address;
}
/**
* @param text $address
*/
public function setAddress($address) {
$this->address = $address;
}
/**
* @return string
*/
public function getCvPath() {
return $this->cv_path;
}
/**
* @param string $cv_path
*/
public function setCvPath($cv_path) {
$this->cv_path = $cv_path;
}
/**
* @return string
*/
public function getFacebookLink() {
return $this->facebook_link;
}
/**
* @param string $facebook_link
*/
public function setFacebookLink($facebook_link) {
$this->facebook_link = $facebook_link;
}
/**
* @return string
*/
public function getTwitterLink() {
return $this->twitter_link;
}
/**
* @param string $twitter_link
*/
public function setTwitterLink($twitter_link) {
$this->twitter_link = $twitter_link;
}
/**
* @return string
*/
public function getInstagramLink() {
return $this->instagram_link;
}
/**
* @param string $instagram_link
*/
public function setInstagramLink($instagram_link) {
$this->instagram_link = $instagram_link;
}
/**
* @return string
*/
public function getLinkedinLink() {
return $this->linkedin_link;
}
/**
* @param string $linkedin_link
*/
public function setLinkedinLink($linkedin_link) {
$this->linkedin_link = $linkedin_link;
}
/**
* @return string
*/
public function getImgPath() {
return $this->img_path;
}
/**
* @param string $img_path
*/
public function setImgPath($img_path) {
$this->img_path = $img_path;
}
/**
* @return date
*/
public function getUniversityGraduatedAt() {
return $this->university_graduated_at;
}
/**
* @param date $university_graduated_at
*/
public function setUniversityGraduatedAt($university_graduated_at) {
$this->university_graduated_at = $university_graduated_at;
}
/**
* @return date
*/
public function getMdGraduatedAt() {
return $this->md_graduated_at;
}
/**
* @param date $md_graduated_at
*/
public function setMdGraduatedAt($md_graduated_at) {
$this->md_graduated_at = $md_graduated_at;
}
/**
* @return date
*/
public function getAssociateProfessorGraduatedAt() {
return $this->associate_professor_graduated_at;
}
/**
* @param date $associate_professor_graduated_at
*/
public function setAssociateProfessorGraduatedAt($associate_professor_graduated_at) {
$this->associate_professor_graduated_at = $associate_professor_graduated_at;
}
}
用户服务:
public function getUserByEmailAndPassword($email, $password, $ip, $user_agent) {
$repository = $this->getEntityManager()->getRepository('AppEntityUsers');
$user = $repository->createQueryBuilder('u')->innerJoin('u.user_information', 'ui')->where('u.email = :email')->setParameter('email', $email);
我想离开用User_information加入一对一用户。
用户信息具有uid为unique_key,并参考用户ID。
如何离开加入并从User_information获取uid =用户ID的数据?
您必须在实体之间建立关系。如果您想要一个OneToone关系:
class User
{
/**
* @ORMId
*/
protected $id;
/**
* @ORMOneToOne(targetEntity="UserInformation")
*/
protected $userInformation;
}
class UserInformation
{
/**
* @ORMId
*/
protected $id;
/**
* @ORMOneToOne(targetEntity="User", inversedBy="userInformation")
* @ORMJoinColumn(name="user_id", referencedColumnName="id")
*/
protected $uid;
}
内在加入:
$user = $repository
->createQueryBuilder('u')
->addSelect('ui') // to limit queries when doing $user->getUserInformation()
->innerJoin('u.userInformation', 'ui')
->where('u.email = :email')->setParameter('email', $email);