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

Konrad Pilch
Konrad Pilch
2,435 Points

Modals

hi,

Ahould i keep modals in a separate file modals nd then just include them when i need ?

1 Answer

geoffrey
geoffrey
28,736 Points

You could give more details ? Modal windows are built in Javascript, CSS & HTML. Most of the time (from what I've already seen and have done), modals (which are made of HTML and Javascript once again) are creaed inside the HTML, where you want, often after the main content.

Then indeed, you might create a separated file with the Javascript managing how the modals windows work...

But if you are talking about your model.php file, which is the file containing all your functions dealing with the database, all your queries, yes, It's good habit to have them included in a separated file. It's part of the MVC design pattern concept. Which basically separates concerns M = the model, V = the view C = the controller.

Konrad Pilch
Konrad Pilch
2,435 Points

I mean like, when you desing a webiste with OOP in PHP, you will have the website chopped into like widges or small parts where they apear when the user is logged in etc.. right?

SO what i mean is thath on my starting page, when the user will click log in or register, a box will pop up, a modal, and i want to do modals that pop up for other things as well, so should i put the modals in a separate diles eg into : templates - > modals and the files and then just include the modal file . php where i need ?

geoffrey
geoffrey
28,736 Points

If you are talking about a modal allowing people to login, It's according to me not necessary to create a separated PHP file with the code containing the HTML and etc... Why ? Because your modal will probably have an ID which is as you know unique. So, that would be quite a bad idea to include it in different areas, except if you are sure this piece of code will be all the time included once and no more. But once again I've never got the reason to do that.

What I often do is I add the code about the modal in a part of the website which is all the time included. As an example the footer (footer.php).

Most of the time this page is included to build the layout of my website and thus, the code related to the modal all the time available.

Finally, doing what you told doesn't seem bad at all to me, as far as it works...