what is the preferrable way to organize the actual code that "does things", and html (+ a bit of php maybe) which displays them? is this what is called templating? is this what templating programs do (Smarty?)? well, atm, i'm not sure i would want to use any 3rd party software to organize my project code. what i am interested in is how it is done. bascially, i recieve site design in html from a designer, and then what? do i start coding inside the htmls?? i was told it is done this way by one dev, but i would want some separation and organization. there were some discussions here regarding the same, but i still fail to understand how i should start, probably because i lack any examples. if some of you could drop a little example that would definately help me a lot. a link to a correct tutorial could do as well i think, but at first i would need it really simple.
PHP and HTML arrangement
Moderator: General Moderators
PHP and HTML arrangement
hello, i am new here. i've found this forum very recently and i already noticed some nice and intelligent discussions here.
i am a true beginner at PHP, although programming is not something totally new for me (been using Pascal (which i didn't like actually), C/C++, Java (didn't enjoy this one much either)). anyways, i have a few questions regarding php and html code organization in projects. form what i found on the net (tutorials etc), i got the impression that many mix php with html quite a lot, and it can get really messy after some time. so the things i wanted to find out:
what is the preferrable way to organize the actual code that "does things", and html (+ a bit of php maybe) which displays them? is this what is called templating? is this what templating programs do (Smarty?)? well, atm, i'm not sure i would want to use any 3rd party software to organize my project code. what i am interested in is how it is done. bascially, i recieve site design in html from a designer, and then what? do i start coding inside the htmls?? i was told it is done this way by one dev, but i would want some separation and organization. there were some discussions here regarding the same, but i still fail to understand how i should start, probably because i lack any examples. if some of you could drop a little example that would definately help me a lot. a link to a correct tutorial could do as well i think, but at first i would need it really simple.
what is the preferrable way to organize the actual code that "does things", and html (+ a bit of php maybe) which displays them? is this what is called templating? is this what templating programs do (Smarty?)? well, atm, i'm not sure i would want to use any 3rd party software to organize my project code. what i am interested in is how it is done. bascially, i recieve site design in html from a designer, and then what? do i start coding inside the htmls?? i was told it is done this way by one dev, but i would want some separation and organization. there were some discussions here regarding the same, but i still fail to understand how i should start, probably because i lack any examples. if some of you could drop a little example that would definately help me a lot. a link to a correct tutorial could do as well i think, but at first i would need it really simple.
My tips for you if you want clean code, and is gonna put some time in it, is to use XML, extremely powerful and does exactly what one is after, abstracting the HTML from the PHP, and also making it all alot easier, perhaps, XML is often overkill in many common situations.
I myself usually takes a little shortcut, by which I mean, put functions etc in an include (naturally), but take it one step further, encapsulate the features you want in a class/package so that you don't have to start doing DB-queries and so in the code, but instead you call a function, which gives you the final array, and just do some nice forloop on it... still cluttered PHP/HTML, but much much easier to read and maintain, without the need for going deep with XML and so on.
Regarding templating, I like the idea, but the concept commonly used with PHP isn't that good if you ask me, first of all it isn't very powerful, you often get frustrated and have to start changing both PHP and HTML to make modifications, but worst of all, instead of mixing PHP/HTML, you instead clutter down your PHP-scripts, with hundreds of lines of just variable assignments, array assignment and all of that, doesn't make it very easy to maintain either. and for the resourcefanatic it could add a couple of percent (many percent if it is a simple page) to the execution time.
EDIT: templating is pretty limited in what you can do too, without starting to hack too much.
I myself usually takes a little shortcut, by which I mean, put functions etc in an include (naturally), but take it one step further, encapsulate the features you want in a class/package so that you don't have to start doing DB-queries and so in the code, but instead you call a function, which gives you the final array, and just do some nice forloop on it... still cluttered PHP/HTML, but much much easier to read and maintain, without the need for going deep with XML and so on.
Regarding templating, I like the idea, but the concept commonly used with PHP isn't that good if you ask me, first of all it isn't very powerful, you often get frustrated and have to start changing both PHP and HTML to make modifications, but worst of all, instead of mixing PHP/HTML, you instead clutter down your PHP-scripts, with hundreds of lines of just variable assignments, array assignment and all of that, doesn't make it very easy to maintain either. and for the resourcefanatic it could add a couple of percent (many percent if it is a simple page) to the execution time.
EDIT: templating is pretty limited in what you can do too, without starting to hack too much.