简体   繁体   English

为什么Symfony渲染来自不同项目的捆绑包?

[英]Why Symfony renders bundle from different project?

I have two projects and I came back to developing the first one. 我有两个项目,而我又回到了第一个项目的开发。 Before I had created the second one everything was fine. 在创建第二个之前,一切都很好。 Now when I launch this function: 现在,当我启动此功能时:

/**
* @Route("/admin", name="admin_page")
*/

public function indexAction()
{

  return $this->render('DevTaskBundle:User:login.html.twig');
}

I see an error related to bundle in the second project: 我在第二个项目中看到与包相关的错误:

An exception has been thrown during the compilation of a template
("Bundle "GradeBundle" does not exist or it is not enabled. 
Maybe you forgot to add it in the registerBundles() method of your 
AppKernel.php file?") in "DevTaskBundle:User:login.html.twig".

What is going on? 到底是怎么回事? How to explain this? 怎么解释呢? GradeBundle is in the second project. GradeBundle在第二个项目中。 It is the only function where I have such error. 这是我遇到此类错误的唯一功能。 Other work fine as they were. 其他工作都很好。 I have never had GradeBundle in this project. 我从未在此项目中拥有GradeBundle。

This is AppKernel.php 这是AppKernel.php

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            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 Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new Dev\TaskBundle\DevTaskBundle(),

        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
    }
}

template login.html.twig 模板login.html.twig

<!DOCTYPE html>
<html>
<head>
<title>{% block title %}Hello{% endblock %}</title>
{% block stylesheets %}
        <link href="{{ asset('bundles/devtask/css/stylesheet.css') }}" type="text/css" rel="stylesheet" />
        <link href="{{ asset('bundles/devtask/css/bootstrap.css') }}" type="text/css" rel="stylesheet" />
    {% endblock %}
</head>

{% block body -%}
<body class="fullBody">




<div class="panelContener">
<form action="{{ path('login_route') }}" method="post">
     <div class="form-group">
    <label for="username">Username:</label>
    <input type="text" id="username" name="name"  style="color:black;"/>
</div>
 <div class="form-group">
    <label for="password">Password:</label>
    <input type="password" id="password" name="pass" style="color:black;" />
</div>

        <input type="hidden" name="_target_path" value="/account" />

    <button type="submit" style="color:black;">login</button>
</form>
</div>

{% javascripts 
'@GradeBundle/Resources/public/js/*' 
'@GradeBundle/Resources/public/js/bootstrap.js'
'@GradeBundle/Resources/public/js/jquery-2.1.4.js'
%}
    <script src="{{ asset_url }}"></script>
{% endjavascripts %}

</body>
    {% endblock %}
</html>

You request assets from the GradeBundle in your template file. 您可以从GradeBundle的模板文件中请求资产。 As a result, the application will try to access to the @GradeBundle resource. 结果,该应用程序将尝试访问@GradeBundle资源。 Since the GradeBundle bundle is not registered to the kernel, it is not possible to resolve the @GradeBundle/Resources/... paths. 由于GradeBundle捆绑包未注册到内核,因此无法解析@GradeBundle/Resources/...路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM