Symfony 3.4 Use the view inside my package

I'm having trouble configuring a new repository using Symfony 3.4. I used the symfony command to create it with the latest LTS (3.4), and I also add a new Bundle command. My new Bundle works and works well, but I cannot use the view stored inside this package.

I will show you the structure of my bundle:

structure

I want to use this index.html.twig in my controller as follows:

<?php

namespace Lister\ListerBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class DefaultController extends Controller
{
    /**
     * @Route("/lister")
     */
    public function indexAction()
    {
        return $this->render('ListerListerBundle:Default:index.html.twig');
    }
}

But when I try to do this, I have this error.

"ListerListerBundle: : index.html.twig" (:/home/emendiel/Data/Code/Perso/WebLister/app/Resources/views,/home/emendiel/Data/Code//WebLister//Symfony/Symfony/SRC/Symfony//Twig///).

, , , symfony , , , Symfony "ListerBundle/Ressources/views"

, .

: .

,

PS: composer.json

"autoload": {
    "psr-4": {
        "": "src/"
    },
    "classmap": [
        "app/AppKernel.php",
        "app/AppCache.php"
    ]
},

PSS: My AppKernel:

public function registerBundles()
{
    $bundles = [
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new AppBundle\AppBundle(),
        new Lister\ListerBundle\ListerListerBundle(),
    ];
...

: My dependencyInjection

enter image description here

:

configuration.php

<?php

namespace Lister\ListerBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
 * This is the class that validates and merges configuration from your app/config files.
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
 */
class Configuration implements ConfigurationInterface
{
    /**
     * {@inheritdoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('lister_lister');

        // Here you should define the parameters that are allowed to
        // configure your bundle. See the documentation linked above for
        // more information on that topic.

        return $treeBuilder;
    }
}

ListerListerExtension.php

<?php

namespace Lister\ListerBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
 * This is the class that loads and manages your bundle configuration.
 *
 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
 */
class ListerListerExtension extends Extension
{
    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }
}

: @Cerad

@ListerLister/Default/index.html.twig

@Cerad

- S3.4 Bundle: Dir: name generate: bundle . , . @ListerLister/Default/index.html.twig . bin/console debug: twig, . - Cerad

+4
2

, S3.4 twig, 'ListerListerBundle: Default: index.html.twig', .

:

'@ListerLister/Default/index.html.twig'

. - , :

bin/console debug:twig

.

S3.3 , , 3.4. , , .

github: https://github.com/sensiolabs/SensioGeneratorBundle/issues/587

, .

: . "ListerListerBundle: Default: index.html.twig" , app/config/config.yml:

# app/config/config.yml
framework:
    templating:
        engines: ['twig']

, , - . .

+12
 "psr-4": {
       "ListerBundle\\": "src/ListerBundle",
    }

, .

$composer dump-autoload
0

Source: https://habr.com/ru/post/1690857/


All Articles