I'm trying to get the URL of my page with Twig.
So I wrote this in my index.html.twig:
{{ app.request.attributes.get("_route") }}
I'm getting this Symfony exception:
Variable "app" does not in exist in "AcmeFoo..."
I had the same problem and sometimes in addition to clearing the cache, it was necessary to rebuild the bootstrap cache. I created a little shell script (cache.sh) like this:
#!/bin/bash
cd /yoursymfonyrootfolder
php app/console cache:clear --env=prod
#path depends on symfony version
php ./vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php
Just place that file in your symfony root folder and execute it with ./cache.sh
Related
I tried to resolve my problem all this morning but I didn't find the solution anywhere.
I have a Symfony project and I use Assetic for my css and js files.
Till today when I ran php bin/console assetic:dump --env=prod, it worked fine.
But now I have this error :
[Symfony\Component\Config\Exception\FileLocatorFileNotFoundException]
The file "C:\wamp\www\PLIE08\app/config/config_=prod.yml" does not exist.
I don't understand why it adds = in my file.
Moreover, after running this command I realized that a folder called "=prod" is created in var/cache in addition to the dev and prod folder.
I tried to update, install composer, clear the cache, look in config file if something was wrong but I'm still blocked...
Somebody can tell me why it searchs the bad file ?
Thanks
try this command bin/console assetic:dump -e prod to verify duplicated =. Otherwise remove the entire content of the cache/prod folder, doest not clear:cache, remove all manually.
I've dumped assets using the folling command:
php app/console assetic:dump
I've got a Runtime exception:
The source file "c:\EasyPHP\data\localweb\projects\symfony\src\LV\IndexBundle/Resources/public/images/" does not exist.
It seems to me strange that:
the / goes to \Resources only, after it is /
the directory images does exist in public
no CSS work. I even tried internal CSS in layout.html.twig. Nothing changes.
OS: Windows 10
Try to remove vendors and re composer install, clear cache directory.
If problem isn't solved after that, please share your config.yml here
I am trying to change the default "web" directory of symfony to something else for example public_html.
I got most of it working by following the manual here -> http://symfony.com/doc/master/cookbook/configuration/override_dir_structure.html
Very last part of that document explains how to change assetic so that assetic:dump will output to the correct directory, so that works, and the website also works.
However the document doesn't seem to explain how to change the output directory of the assets:install command.
When i run this command it still outputs to the web directory.
Does anybody know how to change this ?
assets:install requires a parameter telling where to install the assets:
app/console assets:install path
Just provide your path instead of web.
You can set a path parameter to assets:install
But I think in some case better not overriding the directory structure, preferably making a symlink to the web dir.
This question seems to have been asked multiple times but none of the solutions work for me.
I'm in my prod environment, here is what I've done:
cleared cache before/after doing anything
attempted commenting out the _assetic stuff in config_dev and ensure it isn't anywhere else (not that this should matter in prod env)
set use_controller to both true and false (obviously works with true but doesn't use the compiled files)
Is there anything else I'm missing? The files are generating completely fine from
php app/console assetic:dump --env=prod --no-debug
the file name matches that of in the error minus the route stuff.
I had this problem just one minute ago. Clean up the cache worked for me:
app/console cache:clear --env=prod
Hope this helps.
If clearing the cache or dumping the assets doesn't work. Try noisebleed's comment:
// app/config_dev.yml
assetic:
use_controller: true
bundles: ['FooBarBundle']
Maybe you have removed the assetic routing from the app/routing_dev.yml
_assetic:
resource: .
type: assetic
Faced with the same issue but reason was I name template as "something.twig", not "something.html.twig".
Its seems assetic not scan templates without .html in extension.
As result - template work, but assetic not perform dumping/adding routes for assets from it. Adding .html solve the problem.
Updating the config.yml with a dumb character (newline, white space) remove that error. It seems that by doing that, we force the cache do be re-generated. (Symfony 3.0.0)
maybe is too late but... what worked for me:
php composer.phar install
php app/console cache:clear
php app/console cache:warmup
Like #Marcus said, if you tried:
php bin/console cache:clear
and it didn't help, please clear the your_project_root/var/cache folder manually (remove all folders and files). If you use unix/linux systems, and receive a system message like "Error removing file: Permission denied", you need to change accesses to dir first, for example you can use console command
sudo chmod -R 0777 /your_site_directory/var/cache/
and after this you can clear cache dir.
I encountered this issue in Symfony 3.3 after trying to override my Twig templates directory. Not sure how to fix the issue, but reverting to default templates directory config resolved the issue for now.
# config.yml
twig:
paths: ["%kernel.project_dir%/templates"] # Remove this line to use default dir
After trying all the suggested solutions here, to me it was simply the issue with the name of the template. I had .twig but not .html.twig extension, that's all.
I need an example for command below in Symfony2 :
php app/console doctrine:mongodb:fixtures:load --fixtures=/path/to/fixture
I don't know how to set the --fixtures=/path/to/fixture. I can load all together but I cannot do it for only one new fixture !
What format should /path/to/fixture be ?
Also I tried this --fixtures=src/PMI/UserBundle/DataFixtures/ORM/FeatureFixtures but I get this every time :
[InvalidArgumentException]
Could not find any fixtures to load in:
- src/PMI/UserBundle/DataFixtures/ORM/FeatureFixtures
I know this is old but other people have asked and these answers may not cover some of the other questions.
You only need to specify the folder, not the file. In the above question, its not clear if FeatureFixtures is the php file or actually a folder. It may be failing if that is only a php file and not a folder. This is the correct way to load the fixtures assuming that FeatureFixtures is a php file with the fixtures:
doctrine:fixtures:load --fixtures=src/PMI/UserBundle/DataFixtures/ORM --append
You can define a fixture with the real path.
php app/console doctrine:fixtures:load --fixtures=src/MyBundle/DataFixtures/ORM/LoadMyFixturesData.php
It's not require but if you want to manually specify the directory where the fixtures classes should be loaded you can use this :
for example if I execute a command in directory symfony
--fixtures=/src/yourBundle/fixture
Starting with DoctrineFixturesBundle version 3.1 you need to use doctrine:fixtures:load --group=FeatureFixtures.
For symfony +3 you can use this command:
php bin/console doctrine:fixtures:load --group=YourFixtures --append.
Or short version:
php bin/console d:f:l --group=YourFixtures --append.
where option:
--group Target fixture. If you do not use the option, then load all your fixtures;
--append Without this option the load fixture command will remove all data from your database. Use this option to add new data without removing old data.