本文介绍了Symfony2-捆绑软件出现致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了错误[问题末尾的解决方案]

 致命错误:类'symblog\在第20行
/var/www/Symfony/app/AppKernel.php中找不到Blogger\BlogBu​​ndle\SymblogBu​​ndle'

我提出了一个问题中,但是给出的解决方案对我没有帮助,因为我已经做了建议的工作。我正在学习教程。我在以下位置创建的

  app / config / routing.yml 

a

  *。php资源

谢谢!



我必须在注册捆绑包时添加它通过控制台出现错误

 该命令无法自动配置所有内容。 
您必须手动进行以下更改。

指令:

 -编辑app / autoload.php文件,并在registerNamespaces()调用的顶部注册捆绑
命名空间:
'symblog\Blogger\BlogBu​​ndle'=> ; '/ var / www / Symfony / blog',我紧随其后的是



AppKernel.php

 类AppKernel扩展了内核
{
public函数registerBundles()
{
$ bundles = array(
// ..
new symblog\Blogger\BlogBu​​ndle\SymblogBu​​ndle(),
);

/app/config/routing.yml

  SymblogBu​​ndle:
资源: @ SymblogBu​​ndle / Resources / config / routing.php
前缀:/

根据要求:/app/config/config.yml

 进口:
-{资源:parameters.ini}
-{资源:security.yml}

框架:
#esi:〜
#translator:{fallback:%locale%}
机密:%secret%
字符集:UTF-8
路由器:{资源:%kernel.root_dir%/ config / routing.yml }
格式:true
csrf_protection:true
验证:{enable_annotations:true}
模板:{引擎:['twig']} #assets_version:SomeVersionScheme
会话:
default_locale:%locale%
auto_start:true

#树枝配置
树枝:
调试:%kernel.debug%
严格_variables:%kernel.debug%

#资产配置
资产性:
调试:%kernel.debug%
use_controller:假
#java:/ usr / bin / java
过滤器:
cssrewrite:〜
#闭包:
#jar:%kernel.root_dir%/ java / compiler.jar
#yui_css:
#jar:%kernel.root_dir%/ java / yuicompressor-2.4.2.jar

#教义配置
教义:
dbal:
驱动程序:%database_driver%
主机:%database_host%
端口:%database_port%
dbname:%database_name%
用户:%database_user%
密码:%database_password%
字符集:UTF8

orm:
auto_generate_proxy_classes:%kernel.debug%
auto_mapping:true

#Swiftmailer配置
swiftmailer :
传输:%mailer_transport%
主机:%mailer_host%
用户名:%mail er_user%
密码:%mailer_password%

jms_security_extra:
secure_controllers:真
secure_all_services:假

在@Clamidity回答后,该捆绑包通常位于src / Blogger / SymBlogBu​​ndle / BloggerSymBlogBu​​ndle.php

$ b之后,解决方案非常容易
$ b

在使用控制台进行配置时,它避开了捆绑包的位置,默认设置为/../src,但我更改为/../blog。当然,这是行不通的,Symfony正在寻找错误的位置。我所做的是将/ blog中的文件夹移动到/ src,一切正常。

解决方案

有些事情它可能是。我会介绍所有我能想到的东西。


  1. 通常,捆绑包位于src文件夹中。因此,捆绑包的路径应如下所示。

      src / Blogger / SymBlogBu​​ndle / BloggerSymBlogBu​​ndle.php 

    (请注意,捆绑包名称遵循文件名约定)


  2. 在BloggerSymBlogBu​​ndle.php内部,请确保您具有与以下内容相似的东西:

     <?php 

    命名空间Blogger\SymBlogBu​​ndle;

    使用Symfony\Component\HttpKernel\Bundle\Bundle;

    类BloggerSymBlogBu​​ndle扩展捆绑包
    {
    }

    (请注意,此处也遵循相同的名称约定)


  3. 在您的autoload.php中,应注册的名称空间是包的名称/路径。这是因为分发包本身位于Blogger文件夹中:

     ‘Blogger’=> __DIR __。'/ .. / src',

    (请注意,列出的文件夹是Blogger文件夹)


  4. 现在,在AppKernel.php中,根据您设置并注册的名称空间注册捆绑软件:

      new Blogger\SymBlogBu​​ndle\BloggerSymBlogBu​​ndle(),

    *注意-具有上述配置的资源和对此捆绑包的引用将是

      BloggerSymBlogBu​​ndle 

    因此您的php路由将通过以下方式调用:

      @ BloggerSymBlogBu​​ndle / Resources / config / routing.php 



I've got the error [Solution at the end of the question]

Fatal error: Class 'symblog\Blogger\BlogBundle\SymblogBundle' not found in
/var/www/Symfony/app/AppKernel.php on line 20

I founded the question How to install or integrate bundles in Symfony2, but the solutions given didn't help me, because I already did what is suggested there. I'm following the tutorial symblog.co.uk except that I created at

app/config/routing.yml

a

*.php resource

Thanks in advance!

I have to add that while registering the bundle by console I've got the error

The command was not able to configure everything automatically.
You must do the following changes manually.

And the instructions:

- Edit the app/autoload.php file and register the bundle
namespace at the top of the registerNamespaces() call:
'symblog\Blogger\BlogBundle' => '/var/www/Symfony/blog',

which I followed.

AppKernel.php

class AppKernel extends Kernel
{
public function registerBundles()
{
    $bundles = array(
        //..
        new symblog\Blogger\BlogBundle\SymblogBundle(),
    );

/app/config/routing.yml

SymblogBundle:
resource: "@SymblogBundle/Resources/config/routing.php"
prefix:   /

As requested: /app/config/config.yml

imports:
    - { resource: parameters.ini }
    - { resource: security.yml }

framework:
    #esi:             ~
    #translator:      { fallback: %locale% }
    secret:          %secret%
    charset:         UTF-8
    router:          { resource: "%kernel.root_dir%/config/routing.yml" }
    form:            true
    csrf_protection: true
    validation:      { enable_annotations: true }
    templating:      { engines: ['twig'] } #assets_version: SomeVersionScheme
    session:
        default_locale: %locale%
        auto_start:     true

# Twig Configuration
twig:
    debug:            %kernel.debug%
    strict_variables: %kernel.debug%

# Assetic Configuration
assetic:
    debug:          %kernel.debug%
    use_controller: false
    # java: /usr/bin/java
    filters:
        cssrewrite: ~
        # closure:
        #     jar: %kernel.root_dir%/java/compiler.jar
        # yui_css:
        #     jar: %kernel.root_dir%/java/yuicompressor-2.4.2.jar

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    username:  %mailer_user%
    password:  %mailer_password%

jms_security_extra:
    secure_controllers:  true
    secure_all_services: false

[Edit] The solution was very easy after the answer from @Clamidity that the bundles usually are located at src/Blogger/SymBlogBundle/BloggerSymBlogBundle.php

While the configuration using the console it saked about the location of the bundle and the default was /../src but I changed to /../blog. And of course it won't work, Symfony was looking into the wrong location. What I did was to move the folders inside /blog to /src and everything went fine.

解决方案

There are a few things that it could be. I'll just cover anything I can think of.

  1. Generally bundles are placed in the src folder. So the path to your bundle should look like this.

    src/Blogger/SymBlogBundle/BloggerSymBlogBundle.php
    

    (Notice that the bundle name follows the file name convention)

  2. Inside of the BloggerSymBlogBundle.php make sure you have something similar to the following:

    <?php
    
    namespace Blogger\SymBlogBundle;
    
    use Symfony\Component\HttpKernel\Bundle\Bundle;
    
    class BloggerSymBlogBundle extends Bundle
    {
    }
    

    (Notice that the same name convention is also followed here)

  3. In your autoload.php the namespace that should be registered is the "Blogger" part of the name/path to your bundle. This is because the bundle itself resides in the Blogger folder:

    'Blogger' => __DIR__.'/../src',
    

    (Notice that the folder listed is the parent of the Blogger folder)

  4. Now in the AppKernel.php register the bundle according the namespace your set up and registered:

    new Blogger\SymBlogBundle\BloggerSymBlogBundle(),
    

    *Note - Your resources and references to this bundle with the above configuration would be

    BloggerSymBlogBundle
    

    so your php routing would be called by using:

    @BloggerSymBlogBundle/Resources/config/routing.php
    

这篇关于Symfony2-捆绑软件出现致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:01
查看更多