Jak naprawić wyjątek" Add myBundle to the asseticBundle config " symfony2?
Kiedy próbuję użyć tagu TWIG {% javascript %}
, aby połączyć się z moim plikiem .js
, zwracam go z następującym wyjątkiem:
An exception has been thrown during the compilation of a template ("You must add CompetitiongameBundle to the assetic.bundle config to use the {% javascripts %} tag in CompetitiongameBundle:game:index.html.twig.") in "CompetitiongameBundle:game:index.html.twig".
Moje index.html.twig
wygląda tak:
{% javascripts 'CompetitiongameBundle/Resources/views/public/js/*'%}
<script type="text/javascript" src="{{ asset_url }}" ></script>
{% endjavascripts %}
Hello {{ name }}!
<a href='{{ nexturl }}' >Login</a>
Mój pakiet jest już obecny w pliku konfiguracyjnym, gdy to robię:
php app/console config:dump-reference assetic
Jak mogę to naprawić ? 4 answers
Tak, próbowałem i to rozwiązało problem dla mnie. Dla kogoś (takiego jak ja) kto początkowo nie wie jak dodać to po prostu:
- edit
app/config/config.yml
- Następnie przejdź do
assetic:
- under assetic: go to
bundles: []
- i w
bundles: []
/ / wpisz nazwę pakietu
Na przykład, jeśli Twój Pakiet jest Acme\DemoBundle
, następnie wykonaj następujące czynności
assetic:
bundles: [ AcmeDemoBundle ]
Brak cudzysłowów wokół AcmeDemoBundle
. To wszystko. (Symfony2)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-03-27 21:27:42
Jeśli chcesz, aby assetic domyślnie dołączał twoje pakiety, możesz skomentować (za pomocą #) Pakiety liniowe: []
Ex:
assetic:
debug: "%kernel.debug%"
use_controller: false
#bundles: [ ]
#java: /usr/bin/java
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-01-10 09:51:02
Czasami trzeba podejmować decyzje w locie, wtedy można użyć Use DependencyInjection .
Na przykład do ładuje i zarządza konfiguracją :
<?php
namespace You\ExampeBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/* ... */
class YouExampeExtension extends Extension
{
/* ... */
public function load(array $configs, ContainerBuilder $container)
{
/* ... */
$aAsseticBundle = $container->getParameter('assetic.bundles');
$aAsseticBundle[] = 'YouExampeBundle';
$aAsseticBundle[] = 'AnotheBundle';
$container->setParameter('assetic.bundles', $aAsseticBundle);
/* ... */
}
}
Możesz użyć bardziej złożonej logiki do manipulowania konfiguracją (w rozsądnych granicach)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-03-05 10:43:19
Musisz dodać swój pakiet do bundle: [] wiersz sekcji assetic: w app/config / config.plik yml (symfony 2.1)
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-10-26 21:04:24