About Lesson
Firstly, create a common file in the view folder. In this example, I have created a file name as template.php in the applications/views/innerpages/ directory.
File structure:
applications/view/innerpages - footer.php - header.php - template.php applications/controllers - Welcome.php
1. Create a template.php file in the applications/views/innerpages/ directory.
<?php $this->load->view('innerpages/header.php'); $this->load->view($main_content); $this->load->view('innerpages/footer.php'); ?>
In the above example, $main_content is a dynamic view for each page.
2. Create a header.php file in the applications/views/innerpages/ directory.
<!DOCTYPE html> <html> <head> <title><?php echo $title; ?></title> </head> <body>
3. Create a footer.php file in the applications/views/innerpages/ directory.
<h1><?php $heading; ?></h1> </body> </html>
4. Create a Welcome.php file in the applications/controllers/ directory.
class Welcome extends CI_Controller { public function index() { $data = []; $data[‘title’] = ‘Page Title’; $data[‘heading’] = ‘Welcome to infovistar’ $data[‘main_content’] = ‘about_us’; // page name $this->load->view(‘innerpages/template’, $data); } }