Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

329
Visualizações
How to move Bundle/Resources folder to a subfolder in Symfony?

I'd like to structure a Symfony3 Bundle into submodules.

For this I would like to move the Bundle/Resources folder (with views, config and public) along with the controller classes into a subfolder.

Example with a DemoBundle and the Messages module. The directory should be like this:

+ DemoBundle
    + Directory
    + Posts
    + Messages
       + Controller
           + MessageController.php
       + Resources
           + config
           + public
           + views
               + listing.html.twig

I could move the Controller by making an entry to the routing.yml file like this:

demo-messages:
    resource: "@DemoBundle/Messages/Controller/"
    type:     annotation
    prefix:   /

The Controller now looks like this:

class MessageController extends Controller {
    /**
     * @Route("/messsages", name="Message")
     */
    public function listingAction(Request $request) {
        return $this->render('listing.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
        ]);
    }
}

When I now navigate to this route, I get an error: "Unable to find template". The error says it is still looking in /demo/Resources/views instead of /demo/messages/Resources/views.

Question: Can I somehow tell symfony to look in the folder /demo/messages/Resources/views? Is that possible at all? Or is my template addressing in $this->render(...) wrong?


So far tried the following versions for the template reference:

return $this->render('messages/listing.html.twig', [
                'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
            ]);

Effect: Error: Template not found

~~~

return $this->render('@DemoBundle/Messages/Resources/views/listing.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
        ]);

Works!


The reason I chose this structure over a Bundle for each submodule is that i would like to encapsulate the user interface in this Bundle while i'd like to organize the admin interface in the AdminBundle.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Cerads solution with namespaced template references helped. The following code worked:

return $this->render('@DemoBundle/Messages/Resources/views/listing.html.twig', [
            'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
        ]);

Drawbacks with this workaround are that the short hand template reference is not possible any more and that the copying of the assets (CSS, JS, etc.) doesn't work with php bin/console assets:install

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda