2012-03-03 31 views
2

我appKernel.php看起來是這樣的:爲什麼symfony2不能複製我的包?

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

     if (in_array($this->getEnvironment(), array('dev', 'test'))) { 
      $bundles[] = new Acme\DemoBundle\AcmeDemoBundle(); 
      $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(__DIR__.'/config/config_'.$this->getEnvironment().'.yml'); 
    } 
} 

我autoload.php樣子:

<?php 

use Symfony\Component\ClassLoader\UniversalClassLoader; 
use Doctrine\Common\Annotations\AnnotationRegistry; 

$loader = new UniversalClassLoader(); 
$loader->registerNamespaces(array(
    'Symfony'   => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'), 
    'Sensio'   => __DIR__.'/../vendor/bundles', 
    'JMS'    => __DIR__.'/../vendor/bundles', 
    'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib', 
    'Doctrine\\DBAL' => __DIR__.'/../vendor/doctrine-dbal/lib', 
    'Doctrine'   => __DIR__.'/../vendor/doctrine/lib', 
    'Monolog'   => __DIR__.'/../vendor/monolog/src', 
    'Assetic'   => __DIR__.'/../vendor/assetic/src', 
    'Metadata'   => __DIR__.'/../vendor/metadata/src', 
)); 
$loader->registerPrefixes(array(
    'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib', 
    'Twig_'   => __DIR__.'/../vendor/twig/lib', 
)); 

// intl 
if (!function_exists('intl_get_error_code')) { 
    require_once __DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php'; 

    $loader->registerPrefixFallbacks(array(__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs')); 
} 

$loader->registerNamespaceFallbacks(array(
    __DIR__.'/../src', 
)); 
$loader->register(); 

AnnotationRegistry::registerLoader(function($class) use ($loader) { 
    $loader->loadClass($class); 
    return class_exists($class, false); 
}); 
AnnotationRegistry::registerFile(__DIR__.'/../vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); 

// Swiftmailer needs a special autoloader to allow 
// the lazy loading of the init file (which is expensive) 
require_once __DIR__.'/../vendor/swiftmailer/lib/classes/Swift.php'; 
Swift::registerAutoload(__DIR__.'/../vendor/swiftmailer/lib/swift_init.php'); 

當我這樣做:

php app/console assets:install web 

我得到如下:

Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework 
Installing assets for Acme\DemoBundle into web/bundles/acmedemo 
Installing assets for Symfony\Bundle\WebProfilerBundle into web/bundles/webprofiler 
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution 

爲什麼我的BloggerBlogBu​​ndle沒有被複制過來?

+0

你應該在這裏修改'ticked'的答案;)哈哈 – Jimbo 2013-07-24 10:03:37

回答

16

注:由於OP的回答很短,並沒有真正進入太多的細節,這裏有一個更深入的答案未來的讀者,所以希望你不必做盡可能多的挖掘和我一樣! :)

看來,我們一直遵循完全相同的教程,並有相同的問題,並在上​​述答案是不是很描述,我不得不做一些挖掘自己,這裏的正是怎麼了。

步驟1

src/Blogger/BlogBundle需要有,在/resources文件夾,一個文件夾public/css。所以,你需要把你的CSS文件內容如下:

src/Blogger/BlogBundle/resources/public/css/<stylesheet>.css

創建/public/css文件夾,如果它不存在(它不存在對我來說)。

步驟2 你需要運行assetic管理工具在/web自動爲您創建一個符號鏈接,所以這些可以被訪問。

php app/console assets:install web

現在你會發現,如果你打開(在Linux上使用Windows資源管理器/鸚鵡螺)你的dev目錄,找到/web文件夾,該/web/bundles/bloggerblog/css/<stylesheet>.css已經自動爲您創建!

現在可以使用訪問您的CSS文件中的代碼:

<link href="{{ asset('/bundles/bloggerblog/css/<stylesheet>.css') }}" type="text/css" rel="stylesheet" />

注:」的.css'替換屏幕 'screen.css' 本教程

。 ..應該是這樣!

1

我有與原來的問題完全相同的問題,在運行'php應用程序/控制檯資產:安裝網絡'後資產沒有從捆綁的資源文件夾複製到web/bundles,所以我做的是運行這個命令'php應用程序/控制檯緩存:清除--env = prod',並修復它。正如你所看到的,你正在處理prod資產或者在web目錄中安裝資源來製作環境,所以明確指出產品是合理的。所以這樣做:

1)$的PHP應用程序/控制檯高速緩存:明確--env = PROD 2)$的PHP應用程序/控制檯資產:安裝網絡 或$ PHP應用程序/控制檯資產:安裝網絡--symlink 3)$ php app/console assetic:dump --env = prod(如果您使用內置的Assetic,它會將/ css轉換爲/ web/css中的一個大而不是/ web/bundles)

一切都在那之後到位。你得到/ web/bundles中的所有資產和/ web/css中的資產轉儲,並且所有這些資源都用於prod env。

0

只是有這個問題,確保BlahBundle.php位於相同的目錄資源目錄

0

我有這個問題,今天Symfony3.3.13和問題是public目錄實際上是資本Public,這似乎破壞了安裝腳本。更改名稱並立即生效。

相關問題