How to Deal With Codeigniter Templates?

前端 未结 12 1890
梦谈多话
梦谈多话 2020-12-08 01:02

I\'m fairly new to MVC, and I\'ve found CodeIgniter recently. I\'m still learning everyday, but one problem is its template engine. What is the best way to create templates

12条回答
  •  误落风尘
    2020-12-08 02:01

    Unlike other frameworks CodeIgniter does not have a global template system. Each Controller controls it's own output independent of the system and views are FIFO unless otherwise specified.

    For instance if we have a global header:

    
    
        
            <?=$title?>
            
            
            
            
        
        
            
            

    and a global footer:

            

    then our controller would have to look like

    load->view('header', $data);
    
            $data = array();
            // Content view data
            $this->load->view('my_content_view', $data);
    
            $data = array();
            // Copyright, sitemap, links, etc...
            $this->load->view('footer', $data);
        }
    }
    

    There are other combinations, but better solutions exist through user libraries like:

    See Comments Below

提交回复
热议问题