cache path variable in config.yml for symfony2 - symfony

I was looking to add a separate sub-directory to cache directory for one of the services.
What is a default cache path variable (%cache%) for symfony2?

Wasnt easy to find but its %kernel.cache_dir%

Related

Writable /vendor directory? Simple data storage

I'm creating symfony2 bundle which helps making request to some API.
When user not pass the token value (required in request) then I try to acquire this token and save it in my bundle directory (to read it later). But this path is not writable.
How can I handle simple data storage? Is my approach good or I miss something?
Should my bundle save such values in /vendor directory?
#edit: Asking user to make the directory writable is IMO bad solution
No. /vendor should not be writable by your application. You'll likely overwrite anything you save to /vendor the next time you perform a composer update or composer install.
It sounds like what you need is a persistent piece of configuration information that's outside the scope of your parameters.yml or config.yml (since you want to change it at runtime). Saving into a cache directory doesn't sound appropriate, so you're going to want to store it in some persistent location; probably your database, or a persistent key in redis or other similar storage.
If a cache directory is sufficient, though, you can get the location from the container's kernel.cache_dir parameter; but that will be erased each time the cache is cleared..

How do I automatically include routing and config.yml for bundles in /vendors

I've recently started separating out our custom bundles from our Symfony2 app so that they can be shared across multiple projects. I have successfully got them into their own repositories and included back into the main app via Composer. I know I have to register them in AppKernal, but I was hoping that I wouldn't have to link directly to their routing.yml and config.yml files from the ones in the /app/config/*.yml.
Is there a way to automatically include the config files from bundles within the vendors folder?
It turns out a colleague had done this before with config.yml pointed me to this documentation
http://symfony.com/doc/current/cookbook/bundles/extension.html#using-the-load-method
By adding the following to the load() function in your bundle's extension you can have it auto load the various configuration files
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('config.yml');
$loader->load('services.yml');
However this doesn't work with routing.yml because it thinks it has to load an extension matching the name of each route.
Please see my answer - https://stackoverflow.com/a/58140085/1274890
Also as per https://symfony.com/doc/current/bundles/override.html#routing
Routing is never automatically imported in Symfony. If you
want to include the routes from any bundle, then they must be manually
imported from somewhere in your application (e.g. config/routes.yaml).

Is it possible to pass a route parameter to a configuration loader in Symfony?

I have an application that requires some per-tenant configuration. What I would like to do is load configuration for specific bundles using parameters embedded in the route:
Route: /{tenantId}/some/resource/390234
where I can then load a configuration specific to $tenantId.
As far as I know this is not possible, since configuration loading in symfony2 happens on compile time.
This means every time you do a
php app/console cache:clear
or cache warmup.
Why not do this via configuration entries via database? As an alternative, use a custom class to load e.g. yaml files (don't forget caching) with your own configuration.

Difference between parameters.yml and config.yml in Symfony2

I don't understand the difference between these two ways of setting global constants in Symfony2. Is it only about being able to set default values and types in config.yml (+configuration.php) ?
parameters.yml file is the place for all constants that are environment dependent. If you use composer to deploy your app it will ask you about their values. You can also define paramteters.yml.dist to provide some defaults values. If you use parameters.yml you have all parameters needed to setup an application (for example on production server) in one place.
Nope, nope, nope.
parameters.yml is for passwords and server specific parameters such as database connection information.
The main difference between config.yml (and all the other config files) and parameters.yml is that parameters.yml should never be checked in to your source control system. Doing so will expose your passwords and other private information to whomever has access to your source code.
It is the way to separate some independent data in files. You can put in your config.yml all the data located in another config-files (parameters.yml, routing.yml, security.yml and so on). But it will be hard to maintain the whole project even if you are the single developer on the project.
All config data should be splitted according to their domain. Settings for email - in email-settings file, settings for integrating payment system - in payment-settings file, services - in services-config file.
If you have some personal information in the config files you can add this file to .gitignore and define some default values to the your_config.yml.dist. Then you can set up your composer to run some script to fill your_config.yml file like it has been made in symfony standard edition.

What is the best place of main assets declared in `base.html.twig`

Each bundle has it's own public directory to store assets (css/js/images).
Now what is the best place for assets used in app\Resources\views\base.htl.twg?
How dose Symfony understand to populate them to public?
usually the assets of templates available in the app/Resources/view directory(like base.html.twig) are placed directly in a subdirectory of the web root like web/includes/css/main.css and called with asset('includes/css/main.css').
If you don't like it, you can easily create your own bundle to store the app assets.
I suggest you to create a DesignBundle to store all base template and assets. This method permit you to share your configuration with other application.

Resources