SymfonyCasts stands united with the people of Ukraine

# Symfony 3 Fundamentals: Bundles, Configuration & Environments

41:30

### What you'll be learning

After the first course - Joyful Development with Symfony3, you've got Symfony up and running. CELEBRATION!

In this episode, it's time to get down to work by learning the fundamental concepts of bundles, configuration and environments! We'll discover what all the files in a Symfony project do and why, the purpose of bundles and the power behind environments. So let's get to work: what we're about to learn will pay dividends for us in the future:

• Where do services come from?
• Installing an external bundle
• Configuring bundles
• Controller outside services
• Using config:dump-reference
• Understanding Symfony environments
• The prod environment and cache:clear
• The famous parameters.yml
• Where do routes come from?
• src/ versus app

### Join the Conversation?

42
Login or Register to join the conversation
Constantin | posted 4 years ago

Hey authors! Thanks for this great learning resource. I am migrating from Laravel to Symfony and the way you structured the course makes it a piece of cake. Thanks!

Dude, awesome! Welcome :)

Paul De Zwaan | posted 4 years ago

Authors!, symfony is not disappointing me sofar , before have been doing a lot of stuff in Yii, as i have been wanting to try out symfony for a long time, this was really the help that i needed to switch from framework. So big Thanks! Keep up the good work!

Simon Tran | posted 4 years ago

Your courses is amazing, thank you it all !

My favorite Symfony IDE is Codelobster

Christopher M. | posted 3 years ago

How relatable is this with Symfony 2.6?

Hey Christopher M.!

Hmm, still pretty relatable, but not entirely, of course. The biggest change would be the directory structure - it's a bit different between Symfony 2.6 and 3. However, all the fundamentals of service configuration, bundle configuration, parameters, environments, etc are all pretty much identical between the versions -I think this would serve you well. And if you have questions, you can always ask us :).

Cheers!

WOW! Thanks Ryan & Leanna!

Sams Raina | posted 4 years ago

Hi Team,
Can you share security context tutorial for symfony 2 ?

Hey Sams,

Could you explain a bit more what you mean about "security context tutorial"? Did you see our Symfony Security tutorial? Is it something you're looking for but for Symfony 2 only?

Cheers!

Shairyar Baig | posted 4 years ago

I was looking for a way to allow the admin of a symfony based app to upload a logo via admin panel and then use that logo on every page, I certainly do not want to ping the database on every route just to get the logo. I cannot seem to find any example on how to achieve this. Any tips :)

Hey Shairyar Baig!

Caching! There are 2 ways to cache in Symfony: (A) via the fairly new Symfony cache component or (B) via HTTP caching. Honestly, we need a tutorial on both of these. I would use Symfony's new cache component. Let me give you a few details:

A) I don't know what your database setup looks like, but somewhere in your template, you'll need to fetch the image. Create a new Twig function to do this - so something like:

<img src="{{ get_company_logo() }}"/>

B) In your Twig extension, you'll be able to make a query to find this path. Symfony 3.1 also comes with a new service whose id is cache.app, which you can use to cache the path to the logo. Here are some quick docs about it: http://symfony.com/blog/new...

C) This should be not too hard - just use dependency injection to pass that service to your Twig extension - I know you, so I know you can dig into it ;). But, now what happens when your admin uploads a new logo!? We need to invalidate the cache. Basically, when the user uploads a new image (e.g. you could do this in the controller), you'll need to invalidate the cache you just stored. Details here: http://symfony.com/doc/curr...

And of course, I also need to say "Don't prematurely optimize". Having an extra database query is not ideal... but probably doesn't hurt performance much. So, balance that with the added complexity of caching!

Cheers!

Shairyar Baig | weaverryan | posted 4 years ago | edited

Hi weaverryan many thanks for getting back with your suggestions. I ended up using rendering controller inside twig https://knpuniversity.com/s... which worked out fine, its not a heavy traffic site so an addition ping to db wont hurt the performance. Thanks.

Hey Shairyar Baig

I would suggest you to first focus on functionality, and then, when you detect a bottleneck, optimize your code / cache a few queries

Have a nice day!

Shairyar Baig | MolloKhan | posted 4 years ago

That's exactly what I am doing now :) features are ready just few tweaks here and there. Cache is good idea I will implement that thanks for the tips.

Elbarko Lari | posted 4 years ago

i really enjoyed the first tutorial :p i really want to continu if i had some money for that , any way you are awesome

Hey Elbarko,

Thank you! We'll really miss you too! ;)

Cheers!

Thierno Diop | posted 4 years ago

please can u telle me how did you do to have a terminal like yours in your macbook

Hi Theirno!

Which part - the coloring - or something else? To have a short "prompt" (just the directory at the beginning of each line), I have this code in my ~/.bash_profile file:

export PS1="\w$" I also - obviously - have made my font size really big - Manaco 22pt. And I *am* using the stock "Terminal" application. Does that help? Glad you like it :) Cheers! Reply thx for the reply i mean the cloring of file and folder and can you be more clear about the export ps1 and how to do it and what you mean by stock"terminal" THX you did well with these formations Reply Ah, I understand! Ok: 1) I'm using the normal "terminal" app in OSX. There are other terminal apps you can download - but this is the normal one that comes with OSX. 2) For the file and directory coloring, I added the following 2 lines to my ~/.bash_profile file export CLICOLOR=1export LSCOLORS=GxFxCxDxBxegedabagaced Here is the reference I originally used for this: http://osxdaily.com/2012/02.... After you make the change, open a new terminal tab to see it. 3) If you want to change the text that appears at the beginning of each line in your terminal to look like mine, then you can add the following line to your ~/.bash_profile export PS1="\w$ "

After you make this, open a new terminal tab to see it. This changes the text at the beginning of each terminal line from:

Ryans-MacBook-Pro-4:oo weaverryan$to~/path/to/current/directory$

Cheers!

thx a lot

dominik | posted 4 years ago

Hi Ryan, do you know some tutorial for deploying a Symfony app to a shared hosting, where you are not able to run any console commands? Thanks!

Shairyar Baig | dominik | posted 4 years ago

I am running one of the client's project on shared hosting and its no fun :( i miss having access to CLI to run commands specially when i need to clear cache. It will run without problem but you need to setup .htaccess file in root to point to web folder other wise your every URL will have the word web in it like http://example.com/web

Hi Dominik!

I don't know of any such tutorial. However, the most important thing is that you:

B) Empty the contents of the var/cache directory (app/cache for Symfony 2.x)
C) Make sure the var/cache and var/logs are writeable by the web server (usually done by 777'ing those directories, but this has - in theory - some security implications).

This is a non-standard way to use Symfony, but there's no reason that it shouldn't work.

Good luck!

how about the initial setup, like doctrine:database:create and such.. is there some way to do it by a script instead of cli?

For this, you would dump your local database to an SQL file and import it into your host's database manually (through whatever process they allow you - like phpmyadmin). For database changes in the future, you wouldn't be able to use migrations (like we do in this tutorial) - you would need to make those changes manually (though you could copy the SQL statements from the migration files and execute those manually).

It's not *ideal* to run Symfony without CLI access. It's definitely possible - but as you can see, parts get more complex :)

Mert Simsek | posted 4 years ago

Hi,

I want to get real-time data. Can I do this with redis pub / sub? I own the node.js publisher. I have a symfony subcriber. Can I get the data from node.js and change the twig interface? But i would render twig. How will i send data to twig files?

Yo Mert Simsek!

Hmm, I am far from an expert on this. However, I believe that you need to create some sort of connection between Redis and HTTP so that you can create a socket connection in JavaScript. For example: http://haishibai.blogspot.c... or https://www.compose.com/art.... The solution likely won't have anything to do with Symfony or Twig: you'll just render a page in Symfony/Twig, then create some JavaScript that will create be the subscriber. You don't need a subscriber in Symfony: if you want your frontend to be able to update based on published messages, then your frontend (JS) needs to be the subscriber.

Cheers!

Wiktor Liszkiewicz | posted 4 years ago

Great as always. I really enjoy your tutorials, they make symfony look so easy.
Ps. When will you releas the "Design Pattern" course ?

Hey Wiktor,

Thanks! That's what we're trying to do ;)

"Design Pattern" course was a bit postpone because its author was changed. Unfortunately, the previous one have no time to continue working on it. Probably, we'll start releasing it in a few tutorials, see our rough roadmap: https://knpuniversity.com/c... . Thanks for your patience.

Cheers!

Infete Shine | posted 4 years ago

Hi

Anyone using IvoryCKEditorBundle?

I just want to know how can I add mathjax plugin to it?

Thanks

I haven't used it personally - so sorry, I can't help!

heitoralthmann | posted 4 years ago

Hey heitoralthmann

You can find the download button inside any chapter of a tutorial. So, just click on any chapter link, and then, at the right upper corner you will see that button :)

If you have any other troubles, let us know!

Yan Yong | posted 4 years ago

Thanks Ryan. Your tutorial makes learning symphony quit enjoyable. My suggestion: if you could include a cheatsheet pdf for this course with simple topic that will be very nice.

Thanks Yan Yong!

That's a cool idea! We'll be updating the courses next year for Symfony 4 - I'll consider doing something like that then - it would be neat!

Cheers!

Robert Went | posted 4 years ago

Where do I find the 'coding challenges - practice with real code in an IDE' for each course?

Hey Robert,

Unfortunately, not every course has coding challenges - this course doesn't have them yet. Coding challenges are displayed in course's table of contents, for example, check this one which has coding challenges: https://knpuniversity.com/s... .

But every course has start and finish code, which you can download and open in your IDE if your don't want to code along with the author during the course. On each course chapter page you can find "Download" / "Course code" buttons, however this option available for those users who has paid subscription or own the course.

Cheers!

Robert Went | victor | posted 4 years ago

Ah ok, thanks for the clarification!