Codeigniter Load Views within Views


Codeigniter load views within views : Sometimes we need to load views in another view, it is very simple to load view from another view using the $this->load->view(‘your_view’) method. Here in this article, we are going to explain to how you can load views within views.


Syntax : Codeigniter load views within views

Codeigniter Load Views within Views

We use the below syntax to load in controller, we can use the same syntax to load view in another view.

$this->load->view('your_view');

Example

Here is an example in which we have loaded another view in main view.

<html>
<head>
<title>My Home Page</title>
</head>
<body>
<div id="left-sidebar" style="width:30%;float:left">
<?php $this->load->view('layouts/left_sidebar_view'); ?>
</div>
<div id="content" style="width:60%;float:left">
<h1>Welcome to the home page.</h1>

<p>More Information Goes Here.......</p>
</div>
<div id="right-sidebar" style="width:30%;float:left">
<?php $this->load->view('layouts/right_sidebar_view'); ?>
</div>
</body>
</html>

On the same way we can load multiple views in any view.


Advertisements

Add Comment

📖 Read More