Search code examples
frameworkscodeigniter-2

include other view inside the view


I want include in the view some other view parts, like content1,content2,.etc . Is there a sloution in the Codeigniter, like in Laravel @yield. Sorry if it's dumb question.


Solution

  • I found a solution for that problem, and I would share it. So in the somepage controller need to the page parts calling separatle, and put it in a array:

    public function index()
    {
            $this->_dataOut['head'] = $this->load->view('head','', TRUE);
            $this->_dataOut['header'] = $this->load->view('layout/header','',TRUE);
            $this->_dataOut['body'] = $this->load->view('publicPages/welcome_message','',TRUE);
            $this->_dataOut['footer'] = $this->load->view('layout/footer','',TRUE);
            $this->_dataOut['foot'] = $this->load->view('foot','',TRUE);
            $this->load->view('mainPage', $this->_dataOut);
    }
    

    and than we can call the transferred data by the index like this:

    <?= $head; ?>
    <?= $header; ?>
    <?= $body; ?>
    <?= $footer; ?>
    <?= $foot; ?>
    

    I hope it helpd some one, or not. :) I glad to share, have a nice coding day. :)