Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load a view inside another view

I've been using django for some time and I decided to start a new project but this time in Codeigniter, I used to extend the template file in my views and put content inside the {% block content %} block but it seens to be different in CodeIgniter.

In CodeIgniter I have something like:

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

But is there a way to have an unique file with header, content and footer like this?

<html>
    <head><title>Test</title></head>
    <body>
        <div id="header">Welcome</div>
        <div id="content">
        </div>
        <div id="footer"> 2013 - Tectcom Telecom</div>
    </body>
</html>

And put a view file with a form inside the content div?

like image 788
Leandro Lorenzini de Oliveira Avatar asked Feb 26 '13 18:02

Leandro Lorenzini de Oliveira


People also ask

How to load view inside view in CodeIgniter?

In codeignitor, you must load the views using the function $this->load->view() inside controller.

HOW include external php file in CodeIgniter?

Then in the middle of the file edit the two variables $application_folder and $system_path and make sure you're using an absolute path instead of a relative one. Then in your external PHP script just include the external. php file and use the $CI global object to access the whole codeigniter: include '../../external.


1 Answers

Update your html (layout) file like this:

<div id="content"><?php $this->load->view($content) ?></div>

In your controller, call the view like this:

$view_data = array();
$view_data['content'] = 'form_add_customer';
$this->load->view('path/to/layout', $view_data);
like image 142
minboost Avatar answered Oct 19 '22 03:10

minboost