PHP Programming Tutorial 1 - php codeigniter4 configuration in xampp or wamp
PHP Programming Tutorial 2 - CodeIgniter 4 Application Structure
PHP Programming Tutorial 3 - What is MVC in Codeigniter 4
PHP Programming Tutorial 4 - Codeigniter 4 Environment Variables
PHP Programming Tutorial 5 - Controllers in CodeIgniter 4
PHP Programming Tutorial 6 - Views in CodeIgniter 4
PHP Programming Tutorial 7 - Models in CodeIgniter 4
PHP Programming Tutorial 8 - Remove index.php from URL in CodeIgniter 4
PHP Programming Tutorial 9 - Include header and footer in CodeIgniter 4
PHP Programming Tutorial 10 - Session in CodeIgniter 4
PHP Programming Tutorial 11 - URI Routing in CodeIgniter 4
PHP Programming Tutorial 12 - Highlight Menu using URI Segment in CodeIgniter 4
PHP Programming Tutorial 13 - Connect to Database in CodeIgniter 4
PHP Programming Tutorial 14 - Insert data in Database using CodeIgniter 4
PHP Programming Tutorial 15 - Retrieve data from Database using CodeIgniter 4
PHP Programming Tutorial 16 - Update data in Database using CodeIgniter 4
PHP Programming Tutorial 17 - Delete data in Database using CodeIgniter 4
PHP Programming Tutorial 18 - Generate PDF in CodeIgniter 4
PHP Programming Tutorial 19 - Send Email using PHPMailer in CodeIgniter 4
PHP Programming Tutorial 20 - Upload a File in CodeIgniter 4
🔰 PHP Programming Tutorial 9 - Include header and footer in CodeIgniter 4 🔰
First of all, create a common file in the view folder. In this example, I have created a file name as template.php in /app/Views/innerpages directory. In the above example, $main_content is a dynamic view for each page.
How to include header footer
/app/Views/
+ innerpages
- footer.php
- header.php
- template.php
- home.php
/app/Controllers
- Home.php
/app/Views/innerpages/template.php
<?php
echo view('innerpages/header.php');
echo view($main_content);
echo view('innerpages/footer.php');
?>
/app/Views/innerpages/header.php
<!DOCTYPE html>
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
/app/Views/innerpages/footer.php
<h1><?php echo $heading; ?>
</h1>
</body>
</html>
/app/Controllers/Home.php
namespace App\Controllers;
use App\Controllers\BaseController;
class Home extends BaseController {
public function index() {
$data = [];
$data['title'] = 'Page Title';
$data['heading'] = 'Welcome to chirags.in';
$data['main_content'] = 'home'; // page name
echo view('innerpages/template', $data);
}
}
/app/Views/home.php
<h4> Welcome to Home </h4>
😉Subscribe and like for more videos:
https://www.youtube.com/@chiragstutorial
💛Don't forget to, 💘Follow, 💝Like, 💖Share 💙&, Comment
0 Comments
Leave a message