-->

CSS/JS/Images from Bundle location will be always

2019-07-27 10:25发布

问题:

I have a tiny problem that i don't understand. I have some Bundle project generated by Symfony command, and they create a generic bundle folder in web/bundle/mypersonalbundle. OK, but one of them always be empty when I do an update from composer.phar. And only One! Thanks for your help !

$ php composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
 - Removing doctrine/cache (v1.2.0)
 - Installing doctrine/cache (v1.3.0)
Loading from cache
...

Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for OS\MyPersonalBundleBundle into web/bundles/mypersonalbundle # <--- ?
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution

I'm Ok with updating the FrameworkBundle and DistributionBundle, but Why my personalbundle ?

Here is my composer.json "require" configuration :

"require" : {
    "symfony/symfony" : "2.3.*",
    "symfony/swiftmailer-bundle" : "2.3.*",
    "friendsofsymfony/user-bundle" : "~2.0@dev",
    "doctrine/orm" : ">=2.2.3,<2.4-dev",
    "symfony/assetic-bundle" : "2.3.*",
    "incenteev/composer-parameter-handler" : "~2.0",
    "twig/extensions" : "1.0.*",
    "php" : ">=5.3.3",
    "sensio/generator-bundle" : "2.3.*",
    "symfony/monolog-bundle" : "2.3.*",
    "sensio/framework-extra-bundle" : "2.3.*",
    "doctrine/doctrine-bundle" : "1.2.*",
    "sensio/distribution-bundle" : "2.3.*"
},

My personalBundle is well registered like my other bundles in AppKernel.php :

$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 FOS\UserBundle\FOSUserBundle(),
        new My\PersonalBundleBundle\MyPersonalBundleBundle(),
        new My\PersonalBundle2Bundle\MyPersonalBundle2Bundle(),
        new My\PersonalBundle3Bundle\MyPersonalBundle3Bundle(),
);

回答1:

You have a MyPersonalBundle. In this Bundle, you have a Resources directory. In this directory, you can create a directory named "public" then put your css, js, img files in it. Directory in the public directory are allowed. When you will use composer, it will do the php app/console assets:install command. This command copy the content of the public directory in web/bundle/mypersonalbundle.

Advice : use the extra option in composer.json to create a symlink instead of using the hard copy.

"extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web",
    "symfony-assets-install": "symlink"
}

and the command will be php app/console assets:install --symlink