Call 1 view in Codeigniter but share header/footer among all views? [duplicate]

送分小仙女□ 提交于 2019-12-13 03:06:35

问题


Loving Codeigniter, but I'm finding it annoying that I have to call a header, footer and the main view for each controller.

What is the best way to share a header/footer among all views and minimize replication of code. I don't want to use a template engine.


回答1:


create a view, let's call it template.php with this code

<?php 
$this->load->view('header');
$this->load->view($view);
$this->load->view('footer');
?>

And on your controller do this

//the name of the view file you want to show, in my case I want to open the login_page.php view that's inside the folder user
$data['view'] = 'user/login_page';
//load the data variable so I can use it across the views
$this->load->vars($data);
//load the template.php view that will load header, user/login_page and footer
$this->load->view('template');


来源:https://stackoverflow.com/questions/15093949/call-1-view-in-codeigniter-but-share-header-footer-among-all-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!