Codeigniter: Best way to structure partial views

后端 未结 7 1941
無奈伤痛
無奈伤痛 2020-11-29 19:39

How would you structure the below page in Codeigniter?

\"alt

I thought about creating seperate c

7条回答
  •  清歌不尽
    2020-11-29 20:13

    My Template library can handle all of this. You create a single (or multiple) layout file(s) that contain the partials and a tag for where the main body content will go.

    Syntax as simple as:

    // Set the layout: defaults to "layout" in application/views/layout.php
    $this->template->set_layout('whatever') 
    
    // Load application/views/partials/viewname as a partial
    $this->template->set_partial('partialname', 'partials/viewname');
    
    // Call the main view: application/views/bodyviewname
    $this->template->build('bodyviewname', $data); 
    

    Simples right?

    Put some of that into MY_Controller and its even easier.

提交回复
热议问题