无法使用 TWIG 和 Symfony 2、FOSUserBundle 从 app.user 的用户 table 检索所有字段
Unable to retrieve all fields from user table with app.user using TWIG and Symfony 2, FOSUserBundle
我目前正在制作一个网站,我有一个实体用户,它有几个字段。但是当我尝试检索当前登录的用户时,它只会检索用户名。
UserType中的字段如下:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email')
->add('name')
->add('building')
->add('room')
;
}
我正在使用此 html 代码和 TWIG 检索字段:
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Building</th>
<th>Room Number</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ app.user.name }}</td>
<td>{{ app.user.building }}</td>
<td>{{ app.user.room }}</td>
<td>{{ app.user.email }}</td>
</tr>
</tbody>
</table>
但是当我在浏览器中查看 table 时,我只会在 table?
中填充电子邮件字段
用户实体:
<?php
namespace FYProject\ProjectBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @ORM\Entity
* @ORM\Table(name="fyp_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*/
protected $username;
/**
* @var string
*/
protected $password;
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $lastname;
/**
* @var string
*/
protected $school;
/**
* @var string
*/
protected $qualification;
/**
* @var string
*/
protected $modeofstudy;
/**
* @var string
*/
protected $programmecode;
/**
* @var integer
*/
protected $programmeyear;
/**
* @var datetime
*/
protected $startdate;
/**
* @var string
*/
protected $building;
/**
* @var integer
*/
protected $room;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* @param string $username
* @return Entity
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set password
*
* @param string $password
* @return Entity
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set name
*
* @param string $name
* @return Entity
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set school
*
* @param string $school
* @return Entity
*/
public function setSchool($school)
{
$this->school = $school;
return $this;
}
/**
* Get school
*
* @return string
*/
public function getSchool()
{
return $this->school;
}
/**
* set qualification
*
* @param string qualification
* @return Entity
*/
public function setQualification($qualification){
$this->qualification = $qualification;
return $this;
}
/**
* get qualification
*
* @return string
*/
public function getQualification(){
return $this->qualification;
}
/**
* set modeofstudy
*
* @param string modeofstudy
* @return Entity
*/
public function setModeofstudy($modeofstudy){
$this->modeofstudy = $modeofstudy;
return $this;
}
/**
* get modeofstudy
*
* @return string
*/
public function getModeofstudy(){
return $this->modeofstudy;
}
/**
* set programmecode
*
* @param string programmecode
* @return Entity
*/
public function setProgrammecode($programmecode){
$this->programmecode = $programmecode;
return $this;
}
/**
* get programmecode
*
* @return string
*/
public function getProgrammecode(){
return $this->programmecode;
}
/**
* set programmeyear
*
* @param integer programmeyearn
* @return Entity
*/
public function setProgrammeyear($programmeyear){
$this->programmecode = $programmeyear;
return $this;
}
/**
* get programmecode
*
* @return integer
*/
public function getProgrammeyear(){
return $this->programmeyear;
}
/**
* set startdate
*
* @param datetime startdate
* @return Entity
*/
public function setStartdate($startdate){
$this->startdate = $startdate;
return $this;
}
/**
* get startdate
*
* @return datetime
*/
public function getStartdate(){
return $this->startdate;
}
/**
* set lastname
*
* @param string lastname
* @return Entity
*/
public function setLastname($lastname){
$this->lastname = $lastname;
return $this;
}
/**
* get lastname
*
* @return string
*/
public function getLastname(){
return $this->lastname;
}
/**
* set building
* @param string building
* @return Entity
*/
public function setBuilding($building){
$this->building = $building;
return $this;
}
/**
* get building
*
* @return string
*/
public function getBuilding(){
return $this->building;
}
/**
* set room
* @param integer room
* @return Entity
*/
public function setRoom($room){
$this->room = $room;
return $this;
}
/**
* get room
*
* @return integer
*/
public function getRoom(){
return $this->room;
}
public function __construct(){
parent::__construct();
}
}
当注册当前字段返回空值时,使用 dump(app.user):
User {#306 ▼
#id: 9
#name: null
#lastname: null
#school: null
#qualification: null
#modeofstudy: null
#programmecode: null
#programmeyear: null
#startdate: null
#building: null
#room: null
使用此文档覆盖表单类型
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_forms.md
更新您的数据库架构
清除缓存
问题已解决
我没有为实体用户中的每个字段设置@ORM\column。更新的用户实体:
<?php
namespace FYProject\ProjectBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @ORM\Entity
* @ORM\Table(name="fyp_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=100)
*
*/
protected $name;
/**
* @var string
*
* @ORM\Column(name="lastname", type="string", length=100)
*/
protected $lastname;
/**
* @var string
*
* @ORM\Column(name="school", type="string", length=100)
*/
protected $school;
/**
* @var string
*
* @ORM\Column(name="qualification", type="string", length=50)
*/
protected $qualification;
/**
* @var string
*
* @ORM\Column(name="modeofstudy", type="string", length=50)
*/
protected $modeofstudy;
/**
* @var string
*
* @ORM\Column(name="programmecode", type="string", length=50)
*/
protected $programmecode;
/**
* @var integer
*
* @ORM\Column(name="programmeyear", type="integer", length=10)
*/
protected $programmeyear;
/**
* @var datetime
*
* @ORM\Column(name="startdate", type="datetime", length=50)
*/
protected $startdate;
/**
* @var string
*
* @ORM\Column(name="building", type="string", length=50)
*/
protected $building;
/**
* @var integer
*
* @ORM\Column(name="room", type="integer", length=50)
*/
protected $room;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Entity
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set school
*
* @param string $school
* @return Entity
*/
public function setSchool($school)
{
$this->school = $school;
return $this;
}
/**
* Get school
*
* @return string
*/
public function getSchool()
{
return $this->school;
}
/**
* set qualification
*
* @param string $qualification
* @return Entity
*/
public function setQualification($qualification){
$this->qualification = $qualification;
return $this;
}
/**
* get qualification
*
* @return string
*/
public function getQualification(){
return $this->qualification;
}
/**
* set modeofstudy
*
* @param string $modeofstudy
* @return Entity
*/
public function setModeofstudy($modeofstudy){
$this->modeofstudy = $modeofstudy;
return $this;
}
/**
* get modeofstudy
*
* @return string
*/
public function getModeofstudy(){
return $this->modeofstudy;
}
/**
* set programmecode
*
* @param string $programmecode
* @return Entity
*/
public function setProgrammecode($programmecode){
$this->programmecode = $programmecode;
return $this;
}
/**
* get programmecode
*
* @return string
*/
public function getProgrammecode(){
return $this->programmecode;
}
/**
* set programmeyear
*
* @param integer $programmeyear
* @return Entity
*/
public function setProgrammeyear($programmeyear){
$this->programmecode = $programmeyear;
return $this;
}
/**
* get programmecode
*
* @return integer
*/
public function getProgrammeyear(){
return $this->programmeyear;
}
/**
* set startdate
*
* @param datetime $startdate
* @return Entity
*/
public function setStartdate($startdate){
$this->startdate = $startdate;
return $this;
}
/**
* get startdate
*
* @return datetime
*/
public function getStartdate(){
return $this->startdate;
}
/**
* set lastname
*
* @param string $lastname
* @return Entity
*/
public function setLastname($lastname){
$this->lastname = $lastname;
return $this;
}
/**
* get lastname
*
* @return string
*/
public function getLastname(){
return $this->lastname;
}
/**
* set building
* @param string $building
* @return Entity
*/
public function setBuilding($building){
$this->building = $building;
return $this;
}
/**
* get building
*
* @return string
*/
public function getBuilding(){
return $this->building;
}
/**
* set room
* @param integer $room
* @return Entity
*/
public function setRoom($room){
$this->room = $room;
return $this;
}
/**
* get room
*
* @return integer
*/
public function getRoom(){
return $this->room;
}
public function __construct(){
parent::__construct();
}
}
问题解决了!感谢您的帮助!
我目前正在制作一个网站,我有一个实体用户,它有几个字段。但是当我尝试检索当前登录的用户时,它只会检索用户名。
UserType中的字段如下:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email')
->add('name')
->add('building')
->add('room')
;
}
我正在使用此 html 代码和 TWIG 检索字段:
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Building</th>
<th>Room Number</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ app.user.name }}</td>
<td>{{ app.user.building }}</td>
<td>{{ app.user.room }}</td>
<td>{{ app.user.email }}</td>
</tr>
</tbody>
</table>
但是当我在浏览器中查看 table 时,我只会在 table?
中填充电子邮件字段用户实体:
<?php
namespace FYProject\ProjectBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @ORM\Entity
* @ORM\Table(name="fyp_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*/
protected $username;
/**
* @var string
*/
protected $password;
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $lastname;
/**
* @var string
*/
protected $school;
/**
* @var string
*/
protected $qualification;
/**
* @var string
*/
protected $modeofstudy;
/**
* @var string
*/
protected $programmecode;
/**
* @var integer
*/
protected $programmeyear;
/**
* @var datetime
*/
protected $startdate;
/**
* @var string
*/
protected $building;
/**
* @var integer
*/
protected $room;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* @param string $username
* @return Entity
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set password
*
* @param string $password
* @return Entity
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set name
*
* @param string $name
* @return Entity
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set school
*
* @param string $school
* @return Entity
*/
public function setSchool($school)
{
$this->school = $school;
return $this;
}
/**
* Get school
*
* @return string
*/
public function getSchool()
{
return $this->school;
}
/**
* set qualification
*
* @param string qualification
* @return Entity
*/
public function setQualification($qualification){
$this->qualification = $qualification;
return $this;
}
/**
* get qualification
*
* @return string
*/
public function getQualification(){
return $this->qualification;
}
/**
* set modeofstudy
*
* @param string modeofstudy
* @return Entity
*/
public function setModeofstudy($modeofstudy){
$this->modeofstudy = $modeofstudy;
return $this;
}
/**
* get modeofstudy
*
* @return string
*/
public function getModeofstudy(){
return $this->modeofstudy;
}
/**
* set programmecode
*
* @param string programmecode
* @return Entity
*/
public function setProgrammecode($programmecode){
$this->programmecode = $programmecode;
return $this;
}
/**
* get programmecode
*
* @return string
*/
public function getProgrammecode(){
return $this->programmecode;
}
/**
* set programmeyear
*
* @param integer programmeyearn
* @return Entity
*/
public function setProgrammeyear($programmeyear){
$this->programmecode = $programmeyear;
return $this;
}
/**
* get programmecode
*
* @return integer
*/
public function getProgrammeyear(){
return $this->programmeyear;
}
/**
* set startdate
*
* @param datetime startdate
* @return Entity
*/
public function setStartdate($startdate){
$this->startdate = $startdate;
return $this;
}
/**
* get startdate
*
* @return datetime
*/
public function getStartdate(){
return $this->startdate;
}
/**
* set lastname
*
* @param string lastname
* @return Entity
*/
public function setLastname($lastname){
$this->lastname = $lastname;
return $this;
}
/**
* get lastname
*
* @return string
*/
public function getLastname(){
return $this->lastname;
}
/**
* set building
* @param string building
* @return Entity
*/
public function setBuilding($building){
$this->building = $building;
return $this;
}
/**
* get building
*
* @return string
*/
public function getBuilding(){
return $this->building;
}
/**
* set room
* @param integer room
* @return Entity
*/
public function setRoom($room){
$this->room = $room;
return $this;
}
/**
* get room
*
* @return integer
*/
public function getRoom(){
return $this->room;
}
public function __construct(){
parent::__construct();
}
}
当注册当前字段返回空值时,使用 dump(app.user):
User {#306 ▼
#id: 9
#name: null
#lastname: null
#school: null
#qualification: null
#modeofstudy: null
#programmecode: null
#programmeyear: null
#startdate: null
#building: null
#room: null
使用此文档覆盖表单类型 https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_forms.md
更新您的数据库架构
清除缓存
问题已解决
我没有为实体用户中的每个字段设置@ORM\column。更新的用户实体:
<?php
namespace FYProject\ProjectBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @ORM\Entity
* @ORM\Table(name="fyp_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=100)
*
*/
protected $name;
/**
* @var string
*
* @ORM\Column(name="lastname", type="string", length=100)
*/
protected $lastname;
/**
* @var string
*
* @ORM\Column(name="school", type="string", length=100)
*/
protected $school;
/**
* @var string
*
* @ORM\Column(name="qualification", type="string", length=50)
*/
protected $qualification;
/**
* @var string
*
* @ORM\Column(name="modeofstudy", type="string", length=50)
*/
protected $modeofstudy;
/**
* @var string
*
* @ORM\Column(name="programmecode", type="string", length=50)
*/
protected $programmecode;
/**
* @var integer
*
* @ORM\Column(name="programmeyear", type="integer", length=10)
*/
protected $programmeyear;
/**
* @var datetime
*
* @ORM\Column(name="startdate", type="datetime", length=50)
*/
protected $startdate;
/**
* @var string
*
* @ORM\Column(name="building", type="string", length=50)
*/
protected $building;
/**
* @var integer
*
* @ORM\Column(name="room", type="integer", length=50)
*/
protected $room;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Entity
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set school
*
* @param string $school
* @return Entity
*/
public function setSchool($school)
{
$this->school = $school;
return $this;
}
/**
* Get school
*
* @return string
*/
public function getSchool()
{
return $this->school;
}
/**
* set qualification
*
* @param string $qualification
* @return Entity
*/
public function setQualification($qualification){
$this->qualification = $qualification;
return $this;
}
/**
* get qualification
*
* @return string
*/
public function getQualification(){
return $this->qualification;
}
/**
* set modeofstudy
*
* @param string $modeofstudy
* @return Entity
*/
public function setModeofstudy($modeofstudy){
$this->modeofstudy = $modeofstudy;
return $this;
}
/**
* get modeofstudy
*
* @return string
*/
public function getModeofstudy(){
return $this->modeofstudy;
}
/**
* set programmecode
*
* @param string $programmecode
* @return Entity
*/
public function setProgrammecode($programmecode){
$this->programmecode = $programmecode;
return $this;
}
/**
* get programmecode
*
* @return string
*/
public function getProgrammecode(){
return $this->programmecode;
}
/**
* set programmeyear
*
* @param integer $programmeyear
* @return Entity
*/
public function setProgrammeyear($programmeyear){
$this->programmecode = $programmeyear;
return $this;
}
/**
* get programmecode
*
* @return integer
*/
public function getProgrammeyear(){
return $this->programmeyear;
}
/**
* set startdate
*
* @param datetime $startdate
* @return Entity
*/
public function setStartdate($startdate){
$this->startdate = $startdate;
return $this;
}
/**
* get startdate
*
* @return datetime
*/
public function getStartdate(){
return $this->startdate;
}
/**
* set lastname
*
* @param string $lastname
* @return Entity
*/
public function setLastname($lastname){
$this->lastname = $lastname;
return $this;
}
/**
* get lastname
*
* @return string
*/
public function getLastname(){
return $this->lastname;
}
/**
* set building
* @param string $building
* @return Entity
*/
public function setBuilding($building){
$this->building = $building;
return $this;
}
/**
* get building
*
* @return string
*/
public function getBuilding(){
return $this->building;
}
/**
* set room
* @param integer $room
* @return Entity
*/
public function setRoom($room){
$this->room = $room;
return $this;
}
/**
* get room
*
* @return integer
*/
public function getRoom(){
return $this->room;
}
public function __construct(){
parent::__construct();
}
}
问题解决了!感谢您的帮助!