I have created a symfomy application bundle that can be used to collect crash reports from Android applications (for those interested in Android and ACRA: https://github.com/marvinlabs/acra-server).
People who are ok with that can simply install that application as a regular Symfony 2 bundle, by getting it from GitHub and doing all the command line stuff that is needed BUT I want people to be able to install that application very simply and without:
To do that, I have packaged a zip file containing the whole Symfony code + my bundle. Problem: it seems that the CSS and Javascripts are not properly found, I still need to run a command on the server:
php app/console assetic:dump --env=prod --no-debug
Question 1: How could I get rid of that last step?
Question 2: Overall, what would you add to my process before making the zip file?
Before making that zip file, here is what I do:
I also execute the following commands:
php app/console cache:clear --env=dev
php app/console cache:clear --env=prod
php app/console doctrine:schema:create --env=dev --dump-sql > create-schema.sql
php app/console doctrine:schema:update --env=dev --dump-sql > update-schema.sql
php app/console assets:install --env=prod --no-debug
php app/console assetic:dump --env=prod --no-debug
PS:
Instructions to install for those who want to try troubleshooting it:
Edit 12/06/2013
~/acra-server/web$ ls -l css
total 10
-rw-r--r--+ 1 vincentp users 8990 May 23 18:26 d82d504.css
~/acra-server/web$ ls -l js
total 103
-rw-r--r--+ 1 vincentp users 104721 May 23 18:26 7cb568e.js
:~/acra-server$ ls -l web/js
total 281
-rw-r--r--+ 1 vincentp users 205123 May 28 21:48 7cb568e.js
-rw-r--r--+ 1 vincentp users 21767 May 28 21:48 b96fe74.js
We can see that another JS file has been generated (same goes with CSS). I guess Assetic is not looking for the right files out of the unzip. Any idea on how to correct that? Maybe force assetic to use a given filename?
( assetic's output option )
You are able to configure your asset collection's to dump to a given filename. This can be achieved inside twig with the output option. No more auto-generated filenames like 7cb568e.js.
example:
{% stylesheets
'bundles/mlabsacraserver/stylesheets/*'
filter='cssrewrite'
output='css/stylesheets.css'
%}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
{% endstylesheets %}
... or javascripts ...
{% javascripts
'bundles/mlabsacraserver/js/jquery.min.js'
'bundles/mlabsacraserver/js/*'
output='js/javascripts.js'
%}
<script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}
Now assetic will dump your assets to js/javascripts.js and css/stylesheets.css using the given filters.
The base path where assetic will dump these assets can be configured in your config.yml with assetic.write_to and defaults.to the web/ folder.
you can do even better and keep your code more structured. You can define asset collections inside your config.yml ( or another imported config file ).
The configuration can be found under assetic.assets
example:
# app/config.yml
assetic:
# ...
assets:
js_main:
inputs:
- "bundles/mlabsacraserver/js/jquery.min.js"
- "bundles/mlabsacraserver/js/*"
output: js/javascripts.js
css_main:
inputs:
- "bundles/mlabsacraserver/stylesheets/*"
filters:
- cssrewrite # ...add more if you like
output: css/stylesheets.css
Now you can use these collections inside your twig templates using assetic's asset()
function and the @
-syntax with the corresponding collection names.
example:
<link href="{{ asset('@css_main') }}" type="text/css" rel="stylesheet" />
... and ...
<script src="{{ asset('@js_main') }}" type="text/javascript"></script>
This way you can configure where assetic shall look for your assets , change the names with a single configuration parameter and keep this logic outside of your templates, making them more readable and easier to maintain.
example resulting output:
<link href="/web/css/stylesheets.css" type="text/css" rel="stylesheet" />
<script src="/web/js/javascripts.js" type="text/javascript"></script>
You now have a single configuration point in your application where you add and remove assets using collections and then just use their reference name in your templates.
You can have your users enter their MySQL host, user and password and let symfony write the parameters file for you.
This is what the symfony standard-edition does using SensioDistributionBundle when you first access your application .
The class performing the actual writing of the parameters.yml is Sensio\DistributionBundle\Configurator\Configurator.
use Sensio\DistributionBundle\Configurator\Configurator;
Now use the configurator in your Installation Controller.
$configurator = new Configurator($this->get('kernel')->getRootDir());
$configurator->mergeParameters(array(
'my_parameter' = 'my_value',
'my_parameter2' = 'my_value2',
));
$configurator->write();
}
The best thing will be looking at the Configurator class itself to understand how it works.
can i haz bounty now? ;-)
If it not critical to you, its possible do not use assetic at all and not combine all assetic files into one. You lose all features like minify, combining and others. Instead you no longer need to run php app/console assetic:dump --env=prod --no-debug
.
To do that - run php app/console assets:install web
. It copy all your assets to web/bundles
folder. Then in base.html.twig
template you can include your assets manually.
{% block stylesheets %}
<link href="{{ asset('bundles/mlabsacraserverbundle/stylesheets/style.css') }}" rel="stylesheet" media="screen">
...
{% endblock %}
{% block javascripts %}
<script src="{{ asset('bundles/mlabsacraserverbundle/js/jquery.min.js')}}"></script>
...
{% endblock %}
This is simlpest way to solve your problem.
Other way is to call command from php code like described in documentation here and live example here. You can make an install page, where run this command and install assets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With