收到此错误:
的实例 Symfony \ Bundle \ FrameworkBundle \ Templating \ EngineInterface必须为 注入FOS \ RestBundle \ View \ ViewHandler渲染模板。
当我尝试使用表单创建用户时(如果我删除“ $formView = $form->createView();
”行没有错误……(肯定要删除“ 'form' => $formView,
”)
我的功能:
/**
* Creates a new user entity.
*
* @Route("/new/admin", name="admin_new")
*/
public function newAction(Request $request)
{
$user = new User();
$form = $this->createForm(UserType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
return $this->redirect('/user');
}
$formView = $form->createView();
return $this->render('admin/user/new_admin.html.twig', array(
'form' => $formView,
'user' => $user
));
}
我的视图树枝(我可以放任何示例作为
hello
,但这不起作用,因此从90%确定错误来自:$ formView = $ form-> createView() ;
和我的用户实体:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* User
*
* @ORM\Table(name="user", uniqueConstraints=
{@ORM\UniqueConstraint(name="user_id_uindex", columns={"id"}),
@ORM\UniqueConstraint(name="user_username_uindex", columns=
{"username"})}, indexes={@ORM\Index(name="user_profile_id_fk",
columns={"id_profile"}), @ORM\Index(name="user_localisation_id_fk",
columns={"id_location"})})
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
* @UniqueEntity("username", groups={"Default", "Patch"})
*/
class User implements UserInterface
{
const ROLE_USER = 'ROLE_USER';
const ROLE_ADMIN = 'ROLE_ADMIN';
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
* @Serializer\Groups({"Default", "Deserialize", "user_detail"})
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=32)
* @Serializer\Groups({"Default", "Deserialize", "user_detail"})
*/
protected $username;
/**
* @var string
* @Serializer\Type("string")
* @Assert\Expression(
* "this.getPassword() === this.getRetypedPassword()",
* message="Password does not match",
* groups={"Default", "Patch"}
* )
* @Assert\NotBlank(groups={"Default"})
* @Serializer\Groups({"Deserialize"})
*/
protected $retypedPassword;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=255)
* @Serializer\Groups({"Deserialize", "user_detail"})
* @Assert\Regex(
* pattern="/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,}/",
* message="Password must be seven characters long and contain at least one digit code, upper case, and lower case letter!",
* groups={"Default", "Patch"}
* )
*/
protected $password;
/**
* @var boolean
*
* @ORM\Column(name="enabled", type="boolean", nullable=false)
*/
protected $enabled = '1';
/**
* @var \AppBundle\Entity\Localisation
*
* @ORM\ManyToOne(targetEntity="Localisation")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_location", referencedColumnName="id")
* })
*/
protected $idLocation;
/**
* @var \AppBundle\Entity\Profile
*
* @ORM\ManyToOne(targetEntity="Profile")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_profile", referencedColumnName="id")
* })
*/
protected $idProfile;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="User", inversedBy="idUserOne")
* @ORM\JoinTable(name="friend",
* joinColumns={
* @ORM\JoinColumn(name="id_user_one", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="id_user_two", referencedColumnName="id")
* }
* )
*/
protected $idUserTwo;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Place", inversedBy="idUserInvited")
* @ORM\JoinTable(name="list_invited",
* joinColumns={
* @ORM\JoinColumn(name="id_user_invited", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="id_place_invited", referencedColumnName="id")
* }
* )
*/
protected $idPlaceInvited;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Place", mappedBy="idUserPresent")
*/
protected $idPlacePresent;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="Place", inversedBy="idUserPlace")
* @ORM\JoinTable(name="user_place",
* joinColumns={
* @ORM\JoinColumn(name="id_user_place", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="id_place_place", referencedColumnName="id")
* }
* )
*/
protected $idPlacePlace;
/**
* @var array
* @ORM\Column(type="simple_array", length=200)
* @Serializer\Exclude()
*/
protected $roles;
/**
* Constructor
*/
public function __construct()
{
$this->idUserTwo = new \Doctrine\Common\Collections\ArrayCollection();
$this->idPlaceInvited = new \Doctrine\Common\Collections\ArrayCollection();
$this->idPlacePresent = new \Doctrine\Common\Collections\ArrayCollection();
$this->idPlacePlace = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id)
{
$this->id = $id;
}
/**
* @return string|null
*/
public function getUsername()
{
return $this->username;
}
/**
* @param string $username
*/
public function setUsername(string $username)
{
$this->username = $username;
}
/**
* @return string|null
*/
public function getPassword()
{
return $this->password;
}
/**
* @param string $password
*/
public function setPassword(string $password)
{
$this->password = $password;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* @param bool $enabled
*/
public function setEnabled(bool $enabled): void
{
$this->enabled = $enabled;
}
/**
* @return mixed
*/
public function getIdLocation()
{
return $this->idLocation;
}
/**
* @param mixed $idLocation
*/
public function setIdLocation($idLocation): void
{
$this->idLocation = $idLocation;
}
/**
* @return mixed
*/
public function getIdProfile()
{
return $this->idProfile;
}
/**
* @param mixed $idProfile
*/
public function setIdProfile($idProfile): void
{
$this->idProfile = $idProfile;
}
/**
* @return \Doctrine\Common\Collections\Collection
*/
public function getIdUserTwo(): \Doctrine\Common\Collections\Collection
{
return $this->idUserTwo;
}
/**
* @param \Doctrine\Common\Collections\Collection $idUserTwo
*/
public function setIdUserTwo(\Doctrine\Common\Collections\Collection $idUserTwo): void
{
$this->idUserTwo = $idUserTwo;
}
/**
* @return \Doctrine\Common\Collections\Collection
*/
public function getIdPlaceInvited(): \Doctrine\Common\Collections\Collection
{
return $this->idPlaceInvited;
}
/**
* @param \Doctrine\Common\Collections\Collection $idPlaceInvited
*/
public function setIdPlaceInvited(\Doctrine\Common\Collections\Collection $idPlaceInvited): void
{
$this->idPlaceInvited = $idPlaceInvited;
}
/**
* @return \Doctrine\Common\Collections\Collection
*/
public function getIdPlacePresent(): \Doctrine\Common\Collections\Collection
{
return $this->idPlacePresent;
}
/**
* @param \Doctrine\Common\Collections\Collection $idPlacePresent
*/
public function setIdPlacePresent(\Doctrine\Common\Collections\Collection $idPlacePresent): void
{
$this->idPlacePresent = $idPlacePresent;
}
/**
* @return \Doctrine\Common\Collections\Collection
*/
public function getIdPlacePlace(): \Doctrine\Common\Collections\Collection
{
return $this->idPlacePlace;
}
/**
* @param \Doctrine\Common\Collections\Collection $idPlacePlace
*/
public function setIdPlacePlace(\Doctrine\Common\Collections\Collection $idPlacePlace): void
{
$this->idPlacePlace = $idPlacePlace;
}
/**
* @return string
*/
public function getRetypedPassword(): string
{
return $this->retypedPassword;
}
/**
* @param string $retypedPassword
*/
public function setRetypedPassword(string $retypedPassword): void
{
$this->retypedPassword = $retypedPassword;
}
/**
* Returns the roles granted to the user.
*
* <code>
* public function getRoles()
* {
* return array('ROLE_USER');
* }
* </code>
*
* Alternatively, the roles might be stored on a ``roles`` property,
* and populated in any number of different ways when the user object
* is created.
*
* @return (Role|string)[] The user roles
*/
public function getRoles()
{
return $this->roles;
}
/**
* @param array $roles
*/
public function setRoles(array $roles)
{
$this->roles = $roles;
}
/**
* Returns the salt that was originally used to encode the password.
*
* This can return null if the password was not encoded using a salt.
*
* @return string|null The salt
*/
public function getSalt()
{
// TODO: Implement getSalt() method.
}
/**
* Removes sensitive data from the user.
*
* This is important if, at any given point, sensitive information like
* the plain-text password is stored on this object.
*/
public function eraseCredentials()
{
// TODO: Implement eraseCredentials() method.
}
}