У меня возникает эта ошибка, когда я пытаюсь выполнить http: // localhost: 8000 / профиль или любой поиск: (1/1) FatalErrorException Ошибка компиляции: уровень доступа к AppBundle \ Entity \ User :: $ id должен быть защищен (как в классе FOS \ UserBundle \ Model \ User) или более слабым
в User.php строке 19
Я просто хочу создать веб-страницу для администратора для своего приложения (эта веб-страница будет похожа на панель управления), и я не знаю, как настроить доступ к этим веб-страницам только для администратора, поэтому я попытался использовать FOSUser с логином, но если есть более быстрый метод просто скажите мне (я пробовал метод: https://symfony.com/doc/current/security/form_login_setup.html, но он не работает, просто перезагрузите страницу, когда я нажимаю кнопку «Отправить».)
пожалуйста, помогите
Мой config.yml:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where
the app is deployed
#
https://symfony.com/doc/current/best_practices/configuration.html#
application-related-configuration
parameters:
locale: en
image_directory: '%kernel.project_dir%/web/uploads/images'
framework:
#esi: ~
translator: { fallbacks: ['%locale%'] }
secret: '%secret%'
router:
resource: '%kernel.project_dir%/app/config/routing.yml'
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
default_locale: '%locale%'
trusted_hosts: ~
session:
#
https://symfony.com/doc/current/reference/configuration/framework.html
#handler-id
handler_id: session.handler.native_file
save_path:
'%kernel.project_dir%/var/sessions/%kernel.environment%'
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
# Twig Configuration
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path:
'%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
fos_user:
registration:
form:
type: AppBundle\Form\RegistrationType
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\Entity\User
service: # this lines
mailer: fos_user.mailer.twig_swift # this lines
from_email:
address: "[email protected]"
sender_name: "Test App"
Мой файл безопасности:
# app/config/security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
default_target_path: /list
always_use_default_target_path : true
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
И это мой пользовательский объект:
<?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;
use FOS\UserBundle\Model\User as BaseUser;
/**
* 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 extends BaseUser
{
const ROLE_USER = 'ROLE_USER';
const ROLE_ADMIN = 'ROLE_ADMIN';
/**
* @var integer
*
* @ORM\Column(name = "id", type = "integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy = "IDENTITY")
* @Serializer\Groups({"Default", "Deserialize", "user_detail"})
*/
private $id;
/**
* @var string
*
* @ORM\Column(name = "username", type = "string", length=32, nullable=false)
* @Serializer\Groups({"Default", "Deserialize", "user_detail"})
*/
private $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"})
*/
private $retypedPassword;
/**
* @var string
*
* @ORM\Column(name = "password", type = "string", length=255, nullable=false)
* @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"}
* )
*/
private $password;
/**
* @var boolean
*
* @ORM\Column(name = "enabled", type = "boolean", nullable=false)
*/
private $enabled = '1';
/**
* @var \AppBundle\Entity\Localisation
*
* @ORM\ManyToOne(targetEntity = "Localisation")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name = "id_location", referencedColumnName = "id")
* })
*/
private $idLocation;
/**
* @var \AppBundle\Entity\Profile
*
* @ORM\ManyToOne(targetEntity = "Profile")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name = "id_profile", referencedColumnName = "id")
* })
*/
private $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")
* }
* )
*/
private $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")
* }
* )
*/
private $idPlaceInvited;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity = "Place", mappedBy = "idUserPresent")
*/
private $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")
* }
* )
*/
private $idPlacePlace;
/**
* @var array
* @ORM\Column(type = "simple_array", length=200)
* @Serializer\Exclude()
*/
private $roles;
/**
* Constructor
*/
public function __construct()
{
parent::__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(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @return string
*/
public function getUsername(): string
{
return $this->username;
}
/**
* @param string $username
*/
public function setUsername(string $username): void
{
$this->username = $username;
}
/**
* @return string
*/
public function getPassword(): string
{
return $this->password;
}
/**
* @param string $password
*/
public function setPassword(string $password): void
{
$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.
}
}
не работает .....
теперь у меня есть это: экземпляр Symfony \ Bundle \ FrameworkBundle \ Templating \ EngineInterface должен быть вставлен в FOS \ RestBundle \ View \ ViewHandler для рендеринга шаблонов.




Как написано, попробуйте заменить "private $ id;" по "защищенному $ id;" ?