PHP include best practices question

前端 未结 10 1758
一生所求
一生所求 2020-11-29 19:40

I have been learning syntax for PHP and practicing it. I come from a .NET background so masterpages always made things pretty easy for me when it came to headers and footer

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 20:00

    What you're doing is ok until you start using "Views" or "Templates" in which case you no longer arrange your content HTML inside the "controller" or "action" running.

    Instead you will load a view and populate it with values which leaves all the HTML source ordering to the view and not your PHP file.

    $view = new View('layout.php');
    $view->header = $header;
    $view->content = 'This is the main content!';
    $view->footer = $footer;
    print $view;
    

    which then loads the layout file which looks something like this:

    
    
        
            ...
        
        
            
            

提交回复
热议问题