Dav*_*ios 8 php symfony symfony-3.4
使用Symfony 3.4配置新的存储库时遇到了一些麻烦.我已经使用symfony命令用最后的LTS(3.4)创建了他,我也使用命令添加了一个新的Bundle.我的新Bundle已经运行良好但我不能使用存储在这个包中的视图.
我告诉你我的Bundle的结构:
我想在我的控制器中使用这个index.html.twig,如下所示:
<?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');
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试渲染它时,我发现了这个错误.
无法找到模板"ListerListerBundle:默认:index.html.twig"(查看:/ home/emendiel/Data/Code/Perso/WebLister/app/Resources/views,/ home/emendiel/Data/Code/Perso/WebLister /供应商/ symfony中/ symfony中/ src目录/ Symfony的/桥梁/嫩枝/资源/视图/表).
我明白这说什么,我的文件夹不是symfony搜索我的视图的地方,但我没有找到我怎么说Symfony进入"ListerBundle/Ressources/views"
在我最古老的项目中没有其他配置的工作.
信息:我使用我的捆绑包作为可重复使用的捆绑包.
问候,
PS:这是我在composer.json中的自动加载部分
"autoload": {
"psr-4": {
"": "src/"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
Run Code Online (Sandbox Code Playgroud)
PSS:我的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(),
];
...
Run Code Online (Sandbox Code Playgroud)
再说一遍:这里我的依赖注入
和文件的内容:
的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;
}
}
Run Code Online (Sandbox Code Playgroud)
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');
}
}
Run Code Online (Sandbox Code Playgroud)
解决方案:来自@Cerad
@ ListerLister /默认/ index.html.twig
来自@Cerad的原始回复
出于某种原因,S3.4不再喜欢Bundle:Dir:name方法来指定twig路径,而generate:bundle命令尚未更新.不确定它是否是错误或功能.上面建议的@ListerLister/Default/index.html.twig路径应该有效.尝试bin/console debug:twig以查看twig命名空间路径. - 塞拉德
Cer*_*rad 37
基本问题似乎是在S3.4中,不再支持twig模板路径,例如'ListerListerBundle:Default:index.html.twig'.
用以下内容替换控制器中的路径:
'@ListerLister/Default/index.html.twig'
Run Code Online (Sandbox Code Playgroud)
一切都应该好.如果您不确定实际的名称空间前缀是什么,则运行:
bin/console debug:twig
Run Code Online (Sandbox Code Playgroud)
列出他们.
S3.3仍然可以正常工作,所以这在3.4中有所改变.假设无论如何都要使用命名空间格式,所以这不是什么大问题.
我确实在github上提出了这个问题:https://github.com/sensiolabs/SensioGeneratorBundle/issues/587
我们将看到维护者必须说些什么.
更新:伟大而强大的Fabpot自己回答了我的问题.如果您想继续使用模板的'ListerListerBundle:Default:index.html.twig'格式,请编辑您的app/config/config.yml文件:
# app/config/config.yml
framework:
templating:
engines: ['twig']
Run Code Online (Sandbox Code Playgroud)
如果您的遗留代码仍使用旧格式,则只应执行此操作.对所有新代码使用twig名称空间.