Chapters
23 Chapters
|
2:20:28
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
11.
Parameters
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial also works great for Symfony 6!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.3.0 || ^8.0.0",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"knplabs/knp-markdown-bundle": "^1.8", // 1.9.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.1
"sentry/sentry-symfony": "^4.0", // 4.0.3
"symfony/asset": "5.0.*", // v5.0.11
"symfony/console": "5.0.*", // v5.0.11
"symfony/debug-bundle": "5.0.*", // v5.0.11
"symfony/dotenv": "5.0.*", // v5.0.11
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/framework-bundle": "5.0.*", // v5.0.11
"symfony/monolog-bundle": "^3.0", // v3.6.0
"symfony/profiler-pack": "*", // v1.0.5
"symfony/routing": "5.1.*", // v5.1.11
"symfony/twig-pack": "^1.0", // v1.0.1
"symfony/var-dumper": "5.0.*", // v5.0.11
"symfony/webpack-encore-bundle": "^1.7", // v1.8.0
"symfony/yaml": "5.0.*" // v5.0.11
},
"require-dev": {
"symfony/maker-bundle": "^1.15", // v1.23.0
"symfony/profiler-pack": "^1.0" // v1.0.5
}
}
3 Comments
Ryan and or amazing Symfony Cast team... I got a tricky one for you regarding parameters,
I recently upgraded our organizations symfony 3.4 app to symfony 5.4.6 Flex.
I have gotten all of the main functions of the application working, although there is one thing that I have been putting off, as its just escaping me on how to do it.
Multi Tenant Parameters
Our old 3.4 Symfony application would be able to intercept the $_SERVER['HTTP_HOST'] and use the first part of the url to determine what set of parameters to load. for example
mathew.example.com would load config/mathew/paramters.yaml
ryan.example.com would load config/ryan/parameters.yaml
Each config file would have organization specific parameters such as DB info, company name, etc.
That way we could have one application, two organizations using it, separated database information for ultimate privacy.
I think it was about the symfony 5.1 mile marker where i noticed that the kernel file changed to remove a lot of that granular control of which config files you could load.
I have modified the V5.4.6 Kernel to work, but for some reason, its not working 100 of the time.
Here is my code
So this totally works. Say I got to mathew.example.com, it loads all the mathew parameters. But if I then open up an incognito tab and go to ryan.example.com it loads mathews parameters and vice versa. It keeps this behavior till I clear the cache.
Some of the other things I have attempted to try and resolve this issue are:
<blockquote> * disable app / system caching
</blockquote>
Thank you for any advise you can give.
Hey @Mathew!
Sorry for my late reply. I believe your problem is due to Symfony's internal caching, the very first time you hit your application, it'll build/compile the Symfony's container and then, it'll be cached (by creating many files inside "var/cache/{env}/Container____/"), so, the next time the application runs, it won't compile the container again, so, your strategy of dynamically choosing which config files to read ain't going to work.
I'm not sure about this, but I think you can override the
Kernel::getCacheDir()method, so, it would return a different directory based on the host. Give it a try and let know if it wordked ;)Cheers!
Before anyone comments about keeping sensitive information such as DB connection info in a config file. I am pulling the data into the config files using AWS:Secrets Manager, so the code itself only shows a reference to the Secrets ID and Key name on AWS, not the actual credentials. :)
"Houston: no signs of life"
Start the conversation!