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 trialTomasz Sporys
11,258 PointsWhy do we use php in out html file making a huge mess? I thought that it's a server side language?
Hi guys. Just general simple question. I am learning front-end but wanted to have some grasp of server side language and know how to make it work together. I am taking "Build a website with PHP" Course and I am kinda confused. I expected to learn how the front-end JavaScript and php wrok hand in hand but instead I learn how to make a mess in html by squeezing php code everywhere. I have a feeling this is not how you build internet services like presented on the video? Please, give me some info what is going on?
2 Answers
Kevin Korte
28,149 PointsGenerally what your learning in those videos is the very start of using php for dynamic websites. No matter what, you're going to have to have some sort of dynamic logic in the view that is going to dynamically add html.
Usually, what you'd end up using is an MVC framework, that would introduce views, and partials to stitch together a web page, and your php code would pass the information to the views, and than you would have your templates do something that that information that was passed to it. That often is still having to loop through an array of data on the view, but that's not too messy.
Sean Hayes
Courses Plus Student 8,106 PointsTomasz,
I haven't gotten to the PHP videos on this site yet, too much candy in the store, but I am building a website using PHP and I've seen that PHP can actually clean up pages and make running updates easier.
- Templates: PHP can be used to build templates for sections of your webpages that are repeated over and over across multiple pages. This way when you need to make changes to multiple pages that use the same bits of code, instead of having to look through many pages, you make one change and it spreads across the site.
- Databases: If you are building a simple, static website, PHP is likely more than you will need. But if you are going to talk to a server side database, like SQL, PHP allows you to communicate with that database and use the data.
- Alternative to JavaScript: Depending on the browser security, JavaScript may be disabled. AFAIK, PHP doesn't have any blocks.
Not sure if this helped or not