In the admin panel of my project, I programmed the ability to change the database name to use. I wrote the new database name in the parameters.ini
, and after that the cache had to be cleaned to load the new config.
What is the best way to clean the cache without running the console command?
Or is there another best practise how to change the current db.
You can use the console command via
exec()
:Or simply empty the cache/ folder if you don't want to use the console command.
@HelpNeeder's answer is good but the ClearCache command is not using the --env option given. It is instead using the current kernel the application is running on.
So for it to work with another environnement than the environnement you call the controller from, you need to tweak the code a bit (I can't edit his answer, it's saying the edit queue is full) so here is a more complete answer:
Then you configure the routes :
And you can now output the result of the command using {{ output }} in your twig template.
If you have an access control, don't forget to set the permission for this route to a SUPER_ADMIN or something, you wouldn't want anyone other than an admin able to clear the cache.
You can call this action to clear a cache:
My working action with rendering of
Success
page. It clear the cache at shutdown.Note, you lose sessions if you didn't configure
session:
in config.yml.Most recent best way (2017). I'm creating this in controller:
i'm clearing cache this way:
https://gist.github.com/basdek/5501165