Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [SF2][SF][Symfony2]Dodanie controllera w sonata admin
Crash89
post 8.04.2018, 14:26:38
Post #1





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

Ostrzeżenie: (0%)
-----


Witam,

Chciałbym dodać controller do sonaty admin w symfony 3.
Ale nie chce mi działać, robiłem to według dokumentacji z symfony, poniżej kod:

  1. class OrdersAdminController extends BaseController
  2. {
  3.  
  4. /**
  5.   * @param ProxyQueryInterface $selectedModelQuery
  6.   * @param Request|null $request
  7.   */
  8. public function batchActionGeneratePdf(ProxyQueryInterface $selectedModelQuery, Request $request = null) {
  9. var_dump($request);
  10. die();
  11. }
  12. }
  13.  
  14. i admin.yml
  15.  
  16. services:
  17. app.admin.orders:
  18. class: AppBundle\Admin\OrdersAdmin
  19. tags:
  20. - { name: sonata.admin, manager_type: orm, group: E-commerce, label: Orders }
  21. arguments:
  22. - null
  23. - AppBundle\Entity\Orders
  24. - AppBundle\Controller\OrdersAdminController
  25. public: true


Błąd jaki mi wyskakuje to:
A `Sonata\AdminBundle\Controller\CRUDController::batchActionGeneratePdf` method must be callable

Chyba ten controller nie jest widziany, bo jak dodam to do bazowego controllera w vendorze to działa.
Go to the top of the page
+Quote Post
ohm
post 8.04.2018, 18:26:50
Post #2





Grupa: Zarejestrowani
Postów: 618
Pomógł: 143
Dołączył: 22.12.2010

Ostrzeżenie: (0%)
-----


BaseController jak rozumiem to jest Sonata\AdminBundle\Controller\CRUDController?
Go to the top of the page
+Quote Post
Crash89
post 8.04.2018, 19:12:03
Post #3





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

Ostrzeżenie: (0%)
-----


Cytat(ohm @ 8.04.2018, 19:26:50 ) *
BaseController jak rozumiem to jest Sonata\AdminBundle\Controller\CRUDController?


Tak
Go to the top of the page
+Quote Post
ohm
post 8.04.2018, 20:01:13
Post #4





Grupa: Zarejestrowani
Postów: 618
Pomógł: 143
Dołączył: 22.12.2010

Ostrzeżenie: (0%)
-----


A w adminie masz dodaną tą akcję do BatchActions?
Go to the top of the page
+Quote Post
Crash89
post 8.04.2018, 20:15:18
Post #5





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

Ostrzeżenie: (0%)
-----


Cytat(ohm @ 8.04.2018, 21:01:13 ) *
A w adminie masz dodaną tą akcję do BatchActions?


Tak, w ten sposób:

  1. /**
  2.   * @param array $actions
  3.   * @return array
  4.   */
  5. public function configureBatchActions($actions)
  6. {
  7. // retrieve the default batch actions (currently only delete)
  8.  
  9. $actions['generate_pdf'] = array(
  10. 'label' => 'generuj pdf',
  11. 'translation_domain' => 'SonataAdminBundle',
  12. 'ask_confirmation' => true
  13. );
  14.  
  15. return $actions;
  16. }


Może plik admin.yml trzeba gdzieś dodać do wczytania, bo po prostu stworzyłem ten plik i go wstawiłem do Resources/config.
Go to the top of the page
+Quote Post
LowiczakPL
post 9.04.2018, 07:48:48
Post #6





Grupa: Zarejestrowani
Postów: 531
Pomógł: 55
Dołączył: 3.01.2016
Skąd: Łowicz

Ostrzeżenie: (0%)
-----


zmień nazwę metody

batchActionGeneratePdf

na

batchGeneratePdfAction


--------------------
Szukam zleceń Symfony, Laravel, Back-End, Front-End, PHP, MySQL ...
Go to the top of the page
+Quote Post
ohm
post 9.04.2018, 09:48:45
Post #7





Grupa: Zarejestrowani
Postów: 618
Pomógł: 143
Dołączył: 22.12.2010

Ostrzeżenie: (0%)
-----


Cytat(Crash89 @ 8.04.2018, 21:15:18 ) *
Może plik admin.yml trzeba gdzieś dodać do wczytania, bo po prostu stworzyłem ten plik i go wstawiłem do Resources/config.


No jeśli się nie ładuje admin, to owszem, ja zazwyczaj dorzucam do services.yml
  1. imports:
  2. - { resource: "sonata.yml" }


Go to the top of the page
+Quote Post
Crash89
post 10.04.2018, 14:38:15
Post #8





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

Ostrzeżenie: (0%)
-----


Udało mi się rozwiązać problem, trzeba było w services.yml dodać argument controllera:

  1. admin.Orders:
  2. class: AppBundle\Admin\OrdersAdmin
  3. arguments: [null, AppBundle\Entity\Orders, AppBundle:OrdersAdmin]
  4. tags:
  5. - { name: sonata.admin, manager_type: orm, group: E-commerce, label: Orders }
  6.  


Dzięki Wam za pomoc.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 23.04.2024 - 18:09