Yo, how are you guys structuring PHP inside HTML? Mine’s turning into spaghetti fast.

vika007

New member
Joined
Apr 23, 2006
Messages
3
Reaction score
0
I'm with you on the spaghetti code, I started using PHP-HTML separation with templates like Blade or Twig, works like a charm. It's a bit of a learning curve at first but definitely worth it for maintainability. If you're just starting out, might wanna check those out.
 

heribo

Member
Joined
Oct 27, 2007
Messages
7
Reaction score
0
I feel you, I've been there too. To be honest, I switched to Twig templating engine for my PHP projects, it's a game changer - separate concerns, clean code, and easy to maintain. It also helps you keep your PHP code out of your HTML templates.
 

kokel 54

Member
Joined
Aug 6, 2019
Messages
6
Reaction score
0
Yeah, I feel your pain with PHP spaghetti. I've been using Composer and PSR-2 to keep my PHP organized, it makes it way easier to work with. I'd also recommend looking into Blade templating for a cleaner separation of presentation and logic.
 

Shapoklyak

Member
Joined
Dec 23, 2006
Messages
20
Reaction score
2
Yeah, I feel ya, my code used to be a mess too till I discovered PHP include files and functions. Now I just focus on one task per file, keeps everything clean and easy to maintain. Give that a shot and let me know how it works out for you.
 

Dmitry2006

New member
Joined
May 16, 2006
Messages
4
Reaction score
0
I'm using a templating engine like Twig to keep my PHP separate from the HTML, makes the code way more manageable. You can also try using a MVC framework like Laravel, it helps to organize your code into different files and folders. I made the switch a few months ago and it's been a total game changer for my project's structure.
 

blendique

New member
Joined
Jul 2, 2017
Messages
4
Reaction score
0
NGMI with raw tags, bro. Just switch to a template engine like Blade or Twig and separate your logic before you go insane.
 

VLAD1337

Member
Joined
Apr 7, 2017
Messages
244
Reaction score
33
Honestly, grab a template engine like Twig or Blade ASAP. Mixing raw logic with your tags is a total nightmare, so keep them separate if you want to save your sanity.
 

kr062nic

Member
Joined
Aug 27, 2007
Messages
6
Reaction score
0
Bro, keep all the heavy logic at the very top of the file and only echo variables in the HTML. You really gotta separate the controller logic from the view or that spaghetti will never end.
 
Top