How to deal with problematic views in PHP

Posted on December 14, 2016

In the beginning of my PHP developer career I encountered problem with view. As a beginner I was including HTML and CSS into code, but because of it, it was very hard to maintain.

Over time and learning new techniques i learned to keep frontend code in separated files, however it was still question which way is better:


there is another way:

In my opinion, none of them is optimal because you have to parse files and use regular expressions, which are a waste of time. Of course, there are caching systems etc. but it is just a workaround, not a solution. When we add JavaScripts, further development and control of code may be problematic.

Recently appeared new technologies like Angular and Webpack. All code is written in JS and project is divided into small sections which have own controller, design and CSS style like in Symfony but it is clearly divided into catalogues. Angular is very simple however it still lacks perfection. Use of this solution highly improves a quality of code which has a positive impact on performance. Structure of the project is easier to read and allows us to avoid unnecessary duplication of HTML which is replaced with a special module. All of it takes a really small amount of time and simplify work but you have to spend a couple of hours at the beginning on preparing the environment, writing modules and configuration.

In my opinion, it is the best combination of the frontend with the backend. API deal with the logic of an application and returns JSONs, and Angular nicely “dresses” it up and at sight making the website more interactive and without refreshing. Angular have built-in filters which simplify sorting and filtering of data.

Junior PHP Developer

  • Krzysiek Pawlak

    Great Mati ! Finally you’ve written sth 😉

    But tbh I was waiting for “Alcohol influence on coding skills”