Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

How do I present different data in same layout efficiently?

So I'm trying to work out the logic of a project here (I'm a beginner).

Here is a simple example.

I have one main page with 5 buttons. (Alex, John, Bob, Max, Lauren)

Click on a button will lead you to their profile page with information containing their "Full Name, BOB, Description etc,)

What I am trying to understand here is Alex, John, Bob and the rest have the same profile layout but with different information.

How do I make code more efficient sp that I can input their data in the same layout/template without having to create a new file, copying and pasting code every time I add a new person or name?

Can you lead me to a specific tutorial on Treehouse?

1 Answer

Kevin Korte
Kevin Korte
28,109 Points

You will want to look into organizing your web page with a MVC approach. MVC stands for model, view, controller.

This would be a great task for just very basic PHP, and you can learn how to do this in the PHP lessons here.

Basically, your view will be your layout with variables where the data for each user will go. Your model would store the data like the name, bio, etc, and your controller will fetch the correct model and give it to the view to be rendered on the browser.