Separate Logic from presentation without using template engine

前端 未结 2 1702
长发绾君心
长发绾君心 2021-01-15 11:25

How can we separate Logic from presentation without using any template engine (traditional php-not OOP) Thank in advance

2条回答
  •  自闭症患者
    2021-01-15 11:36

    PHP itself can be used as a template engine. Just put all your logic before you output anything. Put simply:

    1. Process your input
    2. Assign all the dynamic data to be output to variables
    3. Run your view code. The view code may be in a separate file which you include.
    4. In the view, just use things such as echo and foreach to output the data you put into variables in step 2.

提交回复
热议问题