Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Harry Stromfelt
Harry Stromfelt
2,985 Points

Experience using Symfony framework!

Hi, I have been working on a simple website consisting of a single page, which has a userform that sends data to an SQL database.

I just got onto the subject of security on the server side. A friend told me to look at symfony and build the website in its framework. I have spent some time learning how it works and getting it set up. It looks great, but I am stuck on what is probably the simplest task... Where does the CSS and HTML go? I know that there are files in the project "web" directory, but I can't get an output!

Thanks for your help! Harry

1 Answer

Hey!

Symfony is not my strong point (you will know more than me by now!) but I can point you to some useful documentation things. If I understood correctly, the Symfony framework ships with twig. Twig is a templating engine that makes mixing html and php much easier to read and handle. You may have heard of 'Blade' used by Laravel.

Here's the documentation on creating and using templates.

Incidentally, Hampton Paulk just released a course that uses the php framework Slim. In this project, he also pulls in and uses Slim to build templates. Check out that course here.

As for your css (and javascript and images etc), these are generally called 'assets', and you may find a ready made folder with such a name. You'll be looking for the public directory. The public directory is the same place as where the app starts. It might be in a folder called 'public' or similar, but you'll be able to track it down because it's where you'll be pointing all requests in the .htaccess file. If you put your css anywhere outside a public folder, it won't be reachable from the site.

If you need any explanation for the final paragraph, let me know. I've been meaning to build a project in Symfony and it's a good excuse to download it!

Harry Stromfelt
Harry Stromfelt
2,985 Points

Hi Tom!

Cheers for the reply! I have been working hard over the last week to get a better understanding of Symfony and to get it all working. I have got the hang of twig and how symfony ties all of the files together. If you do ever get started on a Symfony project I would be happy to give you a hand if you get stuck. Might save you a bit of time!

I found the public directory - in Symfony there is a 'web' folder. I find it very interesting how you can have files in other directories referencing to this public directory, but then have those files protected, with only the public directory showing up in the web browser. I noticed what was going on by doing 'inspect element' on a symfony demo project. Could a hacker still get to the twig files even though they are stored elsewhere?

I only have one question with the last paragraph: what is .htaccess? is this basically the web accessible file?

Thanks for your help! Harry

Yo!

No worries, thanks for the offer! I might just have to take you up on that :)

Hmm.. I wouldn't worry about your twig files being hacked - if someone can get into your twig files, they can probably get to more important things too! Don't quote me on this because I'm not a security expert but unless you have access to the server (like via ssh), then those parts of your site should be unaccessible.

Hmm, I think there's a course that might help your out. Check out the 'Cleaning Url's with Rewrite Rules' badge in this course. It's essentially a place where you can write instructions to apache about how to handle certain requests.

Old school web building, your 'routing' would've been done in the htaccess file. You would've said "every URL that looks like 'mysite.com/something-here/' should go to page do-something.php". htaccess can be very complex - this is quite a simple example! It also involves a lot of regex #sadface.

Modern MVC apps moved routing inside the application. htaccess files therefore route all requests into one, single index.php file or start.php file somewhere in a public folder, and the application decides what to do and where to send that request.

Good to learn, but not totally necessary for your current project :)