Best practice for HTML head in PHP

前端 未结 4 2213
不思量自难忘°
不思量自难忘° 2021-01-01 22:36

I currently have a very simple page, with some more complicated backend. I\'ve always done this the same way, but I feel it\'s not right. But I haven\'t come up with much us

4条回答
  •  孤独总比滥情好
    2021-01-01 23:28

    I think most experienced coders would tell you to mix your code and your HTML as little as possible. This means doing all of your calculations, then simply passing any variables needed by the view to the view.

    They would also tell you to look into the MVC design pattern. In PHP, this is where Controller classes take the initial request, perform the correct operations on the correct business Model classes & then pass needed data to a View class, which would render your HTML.

    MVC can go from very simple 3 class variations, to extremely complex "Frameworks" like Zend Framework. If you build your own, look into PHP class autoloading, as it will make your life easier.

提交回复
热议问题