I am wondering what is the best way to organize php in your html webpages.
Do you try as much as possible to pack your php code into function (or other ways I am not aware of) so as to limit having a large chuck of php here and there in your html, and replace them by calling upon the function
or php and html are just mixed.
php and html organization
Moderator: General Moderators
Re: php and html organization
You should always use templates. Try Smarty.
Re: php and html organization
could you elaborate a bit how template works.
i'm new
i'm new
Re: php and html organization
Read about Template Engine.
Re: php and html organization
Thank you.
I am sure iwill hv more questions when I am done reading
ga
I am sure iwill hv more questions when I am done reading
ga
Re: php and html organization
The problem with template engines is that some do way too much like Smarty, and others don't do enough. At what point do we stop letting a template engine dictate logic? It can be a slippery slope and create a lot of overhead. At some point, PHP free html becomes more expensive than not having it.
Re: php and html organization
This isn't entirely true, and Asperon touched on it. "Always" use a template? Hardly. Smarty can over complicate very simple applications. Some will use it as a crutch to ensure that their PHP is separate from their HTML. However, since Smarty can employ quite a bit of logic, it can sometimes only portray an illusion of logic and presentation separation.Technical wrote:You should always use templates. Try Smarty.
The common, and probably least helpful answer, is: "Do what your project requires".
I mainly avoid templates but still try to separate PHP from my HTML. This is done by proper OOP design. Create relevant classes and useful functions. Generally good code design will accomplish what you set out to do with trying to reach ultimate logic/presentation separation: clean and understandable code.