composer パッケージで実装するには、symfony パッケージに移動し、次のコマンドを実行します。
ベンダー パッケージをダウンロード:
選択するパッケージはあなた次第です。この例では、人気のあるパッケージ (bmatzner/jquery-bundle) を使用しています。
php composer.phar require bmatzner/jquery-bundle:2.*
jQuery 2.x の場合
また
php composer.phar require bmatzner/jquery-bundle:1.*
jQuery 1.x の場合
バンドルを AppKernel に追加します。
/* /app/AppKernel.php */
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new Bmatzner\JQueryBundle\BmatznerJQueryBundle(),
///...
アセットをインストールします。
php bin/console assets:install --symlink web
テンプレートに含めるには:
<!-- /app/Resources/views/base.html.twig -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}Welcome!{% endblock %}</title>
{% block stylesheets %}{% endblock %}
<script type="text/javascript" src="{{ asset('bundles/bmatznerjquery/js/jquery.min.js') }}"></script>
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
</head>
<body>
{% block body %}{% endblock %}
{% block javascripts %}{% endblock %}
</body>
</html>
キャッシュの消去:
php bin/console cache:clear --env=dev
php bin/console cache:clear --env=prod