How to create Master Page(Layout) with base design style

前端 未结 4 758
逝去的感伤
逝去的感伤 2020-12-09 12:56

I\'m new in CodeIgniter. I want to create Master Page or Layout with base style that will be contain Menu, footer and etc. I don\'t want to write repeating content in all pa

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 13:01

    What we probably do is separate view files for header, menu, footer, etc.. that is common for all pages. And include them inside each view. like

    $this->view('header');
    $this->view('menu');
    //Some specific content
    $this->view('footer');
    

    If you need same functionality without copying the above to all views, you need to create a function in your controller as follows:

    private function myviewfunction($current_view) 
    {
        $this->load->view('header');
        $this->load->view('menu');
        $this->load->view($current_view);
        $this->load->view('footer');
        return NULL;
    }
    

    and call this function in all your pages (methods)

    $this->myviewfunction('about'); //About is the specific view for the method
    

提交回复
热议问题