2011-06-08 90 views
5

我使用app/console創建了一個新軟件包。試着打印一個簡單的問候,讓我可以繼續前進。我自動加載的命名空間,註冊了捆綁,創建了一個頁面,但Symfony的檢測到異常:Symfony2軟件包未註冊

Bundle "PageBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() function of your AppKernel.php file? 

可是我已經這樣做了。

日誌顯示:

[2011-06-08 23:41:56] request.CRITICAL: InvalidArgumentException: Bundle "PageBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() function of your AppKernel.php file? (uncaught exception) at /Applications/MAMP/htdocs/Symfony/app/bootstrap.php.cache line 634 

我也被清除緩存文件夾開發。任何人都可以幫我弄清楚什麼是錯的。我之前做過這件事,這是我第一次遇到這個問題。與bootstrap.php.cache有關的東西

謝謝!感謝所有的幫助。

CODE:

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\DoctrineBundle\DoctrineBundle(), 
     new Symfony\Bundle\AsseticBundle\AsseticBundle(), 
     new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), 
     new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(), 
    ); 

    if (in_array($this->getEnvironment(), array('dev', 'test'))) { 
     $bundles[] = new Webmuch\PageBundle\WebmuchPageBundle(); 
     $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); 
     $bundles[] = new Symfony\Bundle\WebConfiguratorBundle\SymfonyWebConfiguratorBundle(); 
    } 

    return $bundles; 
} 

束還示出了如在分析器的有源束。

+0

我刪除了緩存和引導文件。然後從控制檯重建引導文件。還是一樣的錯誤。我錯過了什麼? – Aayush 2011-06-08 19:25:34

+2

向我們展示您的registerBundles()函數。 – 2011-06-08 19:29:05

+0

我已將它添加到問題中。謝謝! – Aayush 2011-06-09 16:29:55

回答

5

它看起來不像引導緩存(第634行指向Kernel::getBundles()方法,這是拋出異常)的問題,但以防萬一,有一個腳本會重建它:bin\build_bootstrap.php。緩存的存在是爲了減少Symfony需要加載核心Symfony類所需的數量,只要你使用其中一個測試版,就不太可能存在真正的錯誤。

聽起來這可能是一個命名問題:您的錯誤抱怨缺少PageBundle,但根據您的內核,應該將該包稱爲WebmuchPageBundle。你有沒有在你的routing_dev.yml中正確引用它?一個例子路由設置是:

page: 
    resource: "@WebmuchPageBundle/Controller/DefaultController.php" 
    type:  annotation 

因爲你只定義捆綁的開發&測試環境中,你應該使用routing_dev.yml而不是routing.yml

接下來,檢查捆綁類是否正確命名。你應該有一個文件在您的套裝(如src/Webmuch/PageBundle/WebmuchPageBundle.php)具有以下內容的根:

namespace Webmuch\PageBundle; 
use Symfony\Component\HttpKernel\Bundle\Bundle; 

class WebmuchPageBundle extends Bundle 
{ 
} 

哦,顯然檢查Web服務器的用戶可以讀取你的包目錄。我認爲拋出一個不同的錯誤,但它值得檢查!

3

我之前有過這個錯誤。檢查你的路線! 可能介於你有這樣的臺詞:

webmuch_page_hello_world: 
    pattern: /hello 
    defaults: { _controller: PageBundle:Default:hello } 

有「PageBundle」是不正確的。你應該使用「WebmuchPageBundle」。所以像這樣使用它:WebmuchPageBundle:默認:你好