Separating Logic/Style in PHP properly

前端 未结 3 563
星月不相逢
星月不相逢 2020-12-11 12:18

I\'m just wondering what is the best way to separate logic components from the layout in a PHP web project?

The content is stored in MySQL, the logic is PHP and the

3条回答
  •  情歌与酒
    2020-12-11 12:48

    Just use some template engine.
    The most familiar one is PHP itself.

    here is the very basic example of CRUD application:
    the logic part doing only data manipulation

     $v) $row[$k]=htmlspecialchars($v); 
      } else { 
        $row['name']=''; 
        $row['id']=0; 
      } 
      include 'form.php'; 
    }  
    ?>
    

    and two simple templates responsible for output,
    form.php

    
    


    Return to the list

    and list.php

    
    Add item
    
    
  • Though there are plenty of other template engines, of different kinds and ideologies.

提交回复
热议问题