Best Practices: What's the Best Way for Constructing Headers and Footers?

前端 未结 4 818
花落未央
花落未央 2021-01-30 07:46

What\'s the best way for constructing headers, and footers? Should you call it all from the controller, or include from the view file? I\'m using CodeIgniter, and I\'m wanting

4条回答
  •  无人共我
    2021-01-30 08:18

    You could also try it this way -- define a default view template, which then pulls in the content based on a variable ('content' in my example) passed by the controller.

    In your controller:

    $data['content'] = 'your_controller/index';
    
    // more code...
    
    $this->load->vars($data);
    $this->load->view('layouts/default');
    

    Then define a default layout for all pages e.g. views/layouts/default.php

    // doctype, header html etc.
    
    
    load->view($content) ?>
    // footer html etc.

    Then your views can just contain the pure content e.g. views/your_controller/index.php might contain just the variables passed from the controller / data array

    
    
    // etc.
    

    More details on the CI wiki/FAQ -- (Q. How do I embed views within views? Nested templates?...)

提交回复
热议问题