Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony][Symfony4] Jak wyświetlić kilka szablonów twig w jednej metodzie w kontrolerze
thepiotr
post
Post #1





Grupa: Zarejestrowani
Postów: 43
Pomógł: 2
Dołączył: 2.07.2014

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


Chodzi mi o coś takiego:
  1. echo $this->render('strona/header.html.twig');
  2. echo $this->render('podstrona/index.html.twig');
  3. echo $this->render('strona/footer.html.twig');


Jednakże z echo występuje błąd "The controller must return a "Symfony\Component\HttpFoundation\Response" object but it returned null. Did you forget to add a return statement somewhere in your controller?"
A jeśli zamiast ostatniego echo dam return, czy to będzie dobrze? (wtedy niby nie ma tego błędu)
No ale może też jest jakiś prostszy sposób żeby to zrobić?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
sabat24
post
Post #2





Grupa: Zarejestrowani
Postów: 175
Pomógł: 26
Dołączył: 13.09.2007
Skąd: Gdańsk

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


Na siłę możesz zrobić coś takiego (nie testowałem tego, ale na oko powinno działać)
  1. $html = $this->render('strona/header.html.twig')->getContent();
  2. $html .= $this->render('podstrona/index.html.twig')->getContent();
  3. $html .= $this->render('strona/footer.html.twig')->getContent();
  4.  
  5. $response = new Response();
  6. $response->setContent($html);
  7. return $response;
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 13.10.2025 - 06:37