Я следую шагам из моей книги (на основе symfony 2.0.10, я использую Symfony2.6.1 с FOSUB 2.0).
Я строю проект с CRUD, который отображает данные из db только отлично (контроллер горы внутри My / BackendBundle).
Затем я хочу показать проект только для зарегистрированного пользователя admin (с ROLE_SUPER_ADMIN, который существует в моей таблице for_user внутри db с данными CRUD).
Но при открытии ../web/ исключение его результата Unable to find Mountain entity
. от Mountain controller showAction ($ id)
#\src\My\BackendBundle\Controller\MountainController.php /** * Finds and displays a Mountain entity. * * @Route("/{id}", name="mountain_show") * @Method("GET") * @Template() */ public function showAction($id) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository('MyBackendBundle:Mountain')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find Mountain entity.'); } $deleteForm = $this->createDeleteForm($id); return array( 'entity' => $entity, 'delete_form' => $deleteForm->createView(), );
AppKernel.php
#\app\AppKernel.php new FOS\UserBundle\FOSUserBundle(), new My\UserBundle\MyUserBundle(), new My\BackendBundle\MyBackendBundle(),
security.yml
#\app\config\security.yml security: providers: fos_userbundle: id: fos_user.user_manager encoders: FOS\UserBundle\Model\UserInterface: sha512 firewalls: main: pattern: ^/ logout: true anonymous: true form_login: provider: fos_userbundle csrf_provider: form.csrf_provider login_path: /login use_forward: false check_path: /login_check post_only: true always_use_default_target_path: false default_target_path: / target_path_parameter: _target_path use_referer: false failure_path: null failure_forward: false username_parameter: _username password_parameter: _password csrf_parameter: _csrf_token intention: authenticate access_control: - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/, role: ROLE_SUPER_ADMIN }
config.yml
#\app\config\config.yml imports: - { resource: parameters.yml } - { resource: security.yml } - { resource: services.yml } framework: #esi: ~ translator: ~ secret: "%secret%" router: resource: "%kernel.root_dir%/config/routing.yml" strict_requirements: ~ form: ~ csrf_protection: ~ validation: { enable_annotations: true } templating: engines: ['twig'] #assets_version: SomeVersionScheme default_locale: "%locale%" trusted_hosts: ~ trusted_proxies: ~ session: # default_locale: pl # handler_id set to null will use default session handler from php.ini handler_id: ~ fragments: ~ http_method_override: true # Twig Configuration twig: debug: "%kernel.debug%" strict_variables: "%kernel.debug%" # Assetic Configuration assetic: debug: "%kernel.debug%" use_controller: false bundles: [ ] #java: /usr/bin/java filters: cssrewrite: ~ #closure: # jar: "%kernel.root_dir%/Resources/java/compiler.jar" #yui_css: # jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar" # Doctrine Configuration doctrine: dbal: driver: "%database_driver%" 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 # eg database_path: "%kernel.root_dir%/data/data.db3" # 2. Uncomment database_path in parameters.yml.dist # 3. Uncomment next line: # path: "%database_path%" orm: auto_generate_proxy_classes: "%kernel.debug%" auto_mapping: true # Swiftmailer Configuration swiftmailer: transport: "%mailer_transport%" host: "%mailer_host%" username: "%mailer_user%" password: "%mailer_password%" spool: { type: memory } stof_doctrine_extensions: default_locale: en_US orm: default: tree: false loggable: false timestampable: false sluggable: false translatable: false fos_user: db_driver: orm firewall_name: main user_class: My\UserBundle\Entity\User
routing.yml
#\app\config\routing.yml MyBackendBundle: resource: "@MyBackendBundle/Controller/" type: annotation prefix: / fos_user_security: resource: "@FOSUserBundle/Resources/config/routing/security.xml"
parameters.yml
#\parameters.yml parameters: database_driver: pdo_mysql database_host: 127.0.0.1 database_port: null database_name: koronaziemi database_user: root database_password: null mailer_transport: smtp mailer_host: 127.0.0.1 mailer_user: null mailer_password: null locale: pl secret: ThisTokenIsNotSoSecretChangeIt