Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [SF][Symfony][Symfony2]FOSUserBundle - nie chce mi pokazać formularza do logowania
Forum PHP.pl > Forum > PHP > Frameworki
twojastara
exception o treści Unable to find Mountain entity pochodzący z akcji showAction($id) z tego kontrolera z lini 115

  1. <?php
  2.  
  3. namespace My\BackendBundle\Controller;
  4.  
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  10. use My\BackendBundle\Entity\Mountain;
  11. use My\BackendBundle\Form\MountainType;
  12.  
  13. /**
  14.  * Mountain controller.
  15.  *
  16.  */
  17. class MountainController extends Controller
  18. {
  19.  
  20. /**
  21.   * Lists all Mountain entities.
  22.   *
  23.   * @Route("/", name="mountain")
  24.   * @Method("GET")
  25.   * @Template()
  26.   */
  27. public function indexAction()
  28. {
  29. $em = $this->getDoctrine()->getManager();
  30.  
  31. $entities = $em->getRepository('MyBackendBundle:Mountain')->findAll();
  32.  
  33. return array(
  34. 'entities' => $entities,
  35. );
  36. }
  37. /**
  38.   * Creates a new Mountain entity.
  39.   *
  40.   * @Route("/", name="mountain_create")
  41.   * @Method("POST")
  42.   * @Template("MyBackendBundle:Mountain:new.html.twig")
  43.   */
  44. public function createAction(Request $request)
  45. {
  46. $entity = new Mountain();
  47. $form = $this->createCreateForm($entity);
  48. $form->handleRequest($request);
  49.  
  50. if ($form->isValid()) {
  51. $em = $this->getDoctrine()->getManager();
  52. $em->persist($entity);
  53. $em->flush();
  54.  
  55. return $this->redirect($this->generateUrl('mountain_show', array('id' => $entity->getId())));
  56. }
  57.  
  58. return array(
  59. 'entity' => $entity,
  60. 'form' => $form->createView(),
  61. );
  62. }
  63.  
  64. /**
  65.   * Creates a form to create a Mountain entity.
  66.   *
  67.   * @param Mountain $entity The entity
  68.   *
  69.   * @return \Symfony\Component\Form\Form The form
  70.   */
  71. private function createCreateForm(Mountain $entity)
  72. {
  73. $form = $this->createForm(new MountainType(), $entity, array(
  74. 'action' => $this->generateUrl('mountain_create'),
  75. 'method' => 'POST',
  76. ));
  77.  
  78. $form->add('submit', 'submit', array('label' => 'Create'));
  79.  
  80. return $form;
  81. }
  82.  
  83. /**
  84.   * Displays a form to create a new Mountain entity.
  85.   *
  86.   * @Route("/new", name="mountain_new")
  87.   * @Method("GET")
  88.   * @Template()
  89.   */
  90. public function newAction()
  91. {
  92. $entity = new Mountain();
  93. $form = $this->createCreateForm($entity);
  94.  
  95. return array(
  96. 'entity' => $entity,
  97. 'form' => $form->createView(),
  98. );
  99. }
  100.  
  101. /**
  102.   * Finds and displays a Mountain entity.
  103.   *
  104.   * @Route("/{id}", name="mountain_show")
  105.   * @Method("GET")
  106.   * @Template()
  107.   */
  108. public function showAction($id)
  109. {
  110. $em = $this->getDoctrine()->getManager();
  111.  
  112. $entity = $em->getRepository('MyBackendBundle:Mountain')->find($id);
  113.  
  114. if (!$entity) {
  115. throw $this->createNotFoundException('Unable to find Mountain entity.');
  116. }
  117.  
  118. $deleteForm = $this->createDeleteForm($id);
  119.  
  120. return array(
  121. 'entity' => $entity,
  122. 'delete_form' => $deleteForm->createView(),
  123. );
  124. }
  125.  
  126.  
  127. }
  128.  

pojawia się po tym gdy do aplikacji dodałem FOSUserBundle razem z jego klasami i zmianami w plikach conf

  1.  
  2. #\app\config\routing.yml
  3. MyBackendBundle:
  4. resource: "@MyBackendBundle/Controller/"
  5. type: annotation
  6. prefix: /
  7.  
  8. fos_user_security:
  9. resource: "@FOSUserBundle/Resources/config/routing/security.xml"
  10.  


  1. #\app\config\security.yml
  2. security:
  3. providers:
  4. fos_userbundle:
  5. id: fos_user.user_manager
  6.  
  7. encoders:
  8. FOS\UserBundle\Model\UserInterface: sha512
  9.  
  10. firewalls:
  11. main:
  12. pattern: ^/
  13. logout: true
  14. anonymous: true
  15. form_login:
  16. provider: fos_userbundle
  17. csrf_provider: form.csrf_provider
  18. login_path: /login
  19. use_forward: false
  20. check_path: /login_check
  21. post_only: true
  22. always_use_default_target_path: false
  23. default_target_path: /
  24. target_path_parameter: _target_path
  25. use_referer: false
  26. failure_path: null
  27. failure_forward: false
  28. username_parameter: _username
  29. password_parameter: _password
  30. csrf_parameter: _csrf_token
  31. intention: authenticate
  32.  
  33. access_control:
  34. - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  35. - { path: ^/, role: ROLE_SUPER_ADMIN }
  36.  
destroyerr
No to nie wiem z czym masz teraz problem. Z formularzem logowania czy z tym, że w bazie nie masz encji a chcesz ją pobrać?
Jeśli jednak chodzi o logowanie to niestety ale musisz opisać swoją konfigurację.
twojastara
edytuję na bieżąco 1 post, w którym wszystko było opisane ale coś się skiepściło po którejś edycji i został pusty post.
---

W bazie mam encje.
Mam tabelę z zawartością do wydrukowania, która ładnie się wyświetlała do momentu gdy dodałem FOSUserBundle.
I mam drugą tabelę User wygenerowana przez FOSUB z użytkownikiem.

Wyjątek wywala gdy powinien pojawic się formularz logowania (wg książki z 2012 roku omawiającą Symf2.0.10, ja robię na 2.6.1).

-----

Dodaję do aplikacji wyświetlającej dane przez CRUD, pakiet FOSUserBundle. I w momencie gdy (wg podręcznika z 2012 r) powinien pojawić się formularz do logowania, pojawia się exception.
------

W ogóle co go obchodzi cały ten kontroler Mountain skoro w pierwszej kolejności powinien wyświetlić mi formularz logowania .
seeba
A do AppKernel dopisałeś

Kod
new FOS\UserBundle\FOSUserBundle(),


nie podałeś też jakie zmiany wprowadziłeś w config.yml
twojastara
dodam, że FOSUB z dystrybucji Symfony w omawianej aplikacji został sprawdzony i działał w poprzedniej aplikacji.

security.yml jest wklejony cały, tak samo routing.yml
---------------------------
Napiszę jeszcze inaczej.


Dopóki nie dodam linii 35 #\app\config\security.yml

  1. - { path: ^/, role: ROLE_SUPER_ADMIN }


aplikacja wyświetla zawartość. Po dodaniu linii zaczyna jej brakować encji,z której wcześniej korzystała.
----------------------

config.yml
  1. #\app\config\config.yml
  2. imports:
  3. - { resource: parameters.yml }
  4. - { resource: security.yml }
  5. - { resource: services.yml }
  6.  
  7. framework:
  8. #esi: ~
  9. translator: ~
  10. secret: "%secret%"
  11. router:
  12. resource: "%kernel.root_dir%/config/routing.yml"
  13. strict_requirements: ~
  14. form: ~
  15. csrf_protection: ~
  16. validation: { enable_annotations: true }
  17. templating:
  18. engines: ['twig']
  19. #assets_version: SomeVersionScheme
  20. default_locale: "%locale%"
  21. trusted_hosts: ~
  22. trusted_proxies: ~
  23. session:
  24. # default_locale: pl
  25. # handler_id set to null will use default session handler from php.ini
  26. handler_id: ~
  27. fragments: ~
  28. http_method_override: true
  29.  
  30. # Twig Configuration
  31. twig:
  32. debug: "%kernel.debug%"
  33. strict_variables: "%kernel.debug%"
  34.  
  35. # Assetic Configuration
  36. assetic:
  37. debug: "%kernel.debug%"
  38. use_controller: false
  39. bundles: [ ]
  40. #java: /usr/bin/java
  41. filters:
  42. cssrewrite: ~
  43. #closure:
  44. # jar: "%kernel.root_dir%/Resources/java/compiler.jar"
  45. #yui_css:
  46. # jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
  47.  
  48. # Doctrine Configuration
  49. doctrine:
  50. dbal:
  51. driver: "%database_driver%"
  52. host: "%database_host%"
  53. port: "%database_port%"
  54. dbname: "%database_name%"
  55. user: "%database_user%"
  56. password: "%database_password%"
  57. charset: UTF8
  58. # if using pdo_sqlite as your database driver:
  59. # 1. add the path in parameters.yml
  60. # e.g. database_path: "%kernel.root_dir%/data/data.db3"
  61. # 2. Uncomment database_path in parameters.yml.dist
  62. # 3. Uncomment next line:
  63. # path: "%database_path%"
  64.  
  65. orm:
  66. auto_generate_proxy_classes: "%kernel.debug%"
  67. auto_mapping: true
  68.  
  69. # Swiftmailer Configuration
  70. swiftmailer:
  71. transport: "%mailer_transport%"
  72. host: "%mailer_host%"
  73. username: "%mailer_user%"
  74. password: "%mailer_password%"
  75. spool: { type: memory }
  76.  
  77.  
  78. stof_doctrine_extensions:
  79. default_locale: en_US
  80. orm:
  81. default:
  82. tree: false
  83. loggable: false
  84. timestampable: false
  85. sluggable: false
  86. translatable: false
  87.  
  88. fos_user:
  89. db_driver: orm
  90. firewall_name: main
  91. user_class: My\UserBundle\Entity\User
kpt_lucek
  1. - { path: ^/, role: ROLE_SUPER_ADMIN }

Blokuje Ci dostęp do podstawowych ścieżek.

Zobacz tak:
  1. - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  2. - { path: ^/login_check, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  3. - { path: ^/, roles: ROLE_SUPER_ADMIN }
twojastara
Nic się nie zmieniło po zamianie tych 3 linii w security.yml
-----------------------


dobra, do wyjebania temat. Teraz gdy znam rozwiązanie to nie mogę patrzeć na to co tu pisałem.

3 dni stracone przez pominięcie fragmentu kodu AUTORA podręcznika.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.