엔티티는 일반 PHP 클래스입니다 ... 먼저 U 테이블을 작성한 다음 U 엔티티를 작성해야합니다. 클래스의 속성은 setter 및 getter를 사용하여 private이어야하며 일반적으로 테이블의 field와 동일한 이름을 사용해야합니다. U가 DB에 새로운 레코드를 넣으려고 할 때, 클래스 U의 인스턴스를 만들고 값을 설정 한 다음 엔티티 관리자를 유지하고 플러시해야합니다. 예제 코드 : u는 기록
$found = $entityManager->find('className', $id); // search by id
or $entityManager->getRepository('className')->findOneBy(array('field', 'value'));
에게 기존의 취득하려면
$user = new Entity\User();
$user->setName('users name');
$user->setPassword('password');
$entityManager->persist($user); // put that entity in queue;
$entityManager->flush(); // execute all pending entities
:
<?php
namespace Entity;
/**
* @Entity
* @Table(name="users")
*/
class User {
/** @Id
* @Column(type="integer")
* */
private $id;
/** @Column(type="string") */
private $username;
/** @Column(type="string") */
private $password;
/** @Column(type="boolean") */
private $active;
public function getId() {
return $this->id;
}
public function setId($id) {
$this->id = $id;
}
public function getUsername() {
return $this->username;
}
public function setUsername($username) {
$this->username = $username;
}
public function getPassword() {
return $this->password;
}
public function setPassword($password) {
$this->password = $password;
}
public function getActive() {
return $this->active;
}
public function setActive($active) {
$this->active = $active;
}
}
와 u는 새로운 기록을 넣고 싶을 때