The Codeigniter 4 has been launched. I am going to discuss How to Integrate Bootstrap Theme With Codeigniter 4. I will create a Codeigniter layout using the bootstrap ace theme.
This Codeigniter tutorial help to create a custom layout. This is a master template that will use to render the child view file, which has a partial header, footer, and sidebar file. I have already shared Creating Template in CodeIgniter 3 Using Bootstrap Theme.
I am taking same above bootstrap theme and functionalities, I’ll integrate the bootstrap theme and create a layout in CodeIgniter 4. The layout and file structure is too different from Codeigniter 3 to code 4.
I am assuming – You have configured and installed CodeIgniter 4 into your system, if not configured yet, please install and configure Codeigniter 4 using Install & Configure Codeigniter 4 In XAMPP.
There are the following libs and software that need to configure-
mod_rewrite
module(for Apache)The bootstrap admin theme is the popular bootstrap admin theme.Its a open source free bootstrap theme.You can change theme as per your application need.
I am creating codeigniter-blog
folder into xampp/htdocs/
directory and moved all files and directories from CodeIgniter 4 downloaded folder to xampp/htdocs/codeigniter-blog
folder.
We will create and modify following CI files.
template.php
class.Modify app.php file
We will modify the configuration parameters in app/Config/app.php
file, I made the following changes into this file:
$config['base_url'] = 'http://codeigniter-blog/';
We will create a default_layout.php
view file in the app/Views/ folder. This file will contain all js, css libraries files with HTML inner container variables.
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta charset="utf-8"> <title>Test CI Application - <?php echo $title;?></title> <meta name="description" content="overview & stats"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> <!-- bootstrap & fontawesome --> <link rel="stylesheet" href="<?php echo base_url(" css="" bootstrap.min.css");?="">" /> <link rel="stylesheet" href="<?php echo base_url(" font-awesome="" css="" font-awesome.min.css");?="">" /> <link rel="stylesheet" href="<?php echo base_url(" css="" ace.min.css");?="">" class="theme-stylesheet" id="theme-style" /> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Tangerine"> <!-- page specific plugin styles --> <div id="navbar" class="navbar navbar-default"> <div class="navbar-container" id="navbar-container"> <button type="button" class="navbar-toggle menu-toggler pull-left" id="menu-toggler" data-target="#sidebar"> <span class="sr-only">Toggle sidebar</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <div class="navbar-header pull-left"> <a href="/" class="navbar-brand"> <small> <i class="fa fa-leaf"></i> Sample CI Example </small> </a> </div> <div class="navbar-buttons navbar-header pull-right" role="navigation"> <ul class="nav ace-nav"> <li class="light-blue"> <a data-toggle="dropdown" href="#" class="dropdown-toggle"> <img class="nav-user-photo" src="<?php echo base_url(" avatars="" user.jpg");?="">" alt="Admin Photo" /> <span class="user-info"> <small>Welcome,</small> Admin </span> <i class="ace-icon fa fa-caret-down"></i> </a> <ul class="user-menu dropdown-menu-right dropdown-menu dropdown-yellow dropdown-caret dropdown-close"> <li> <a href="#"> <i class="ace-icon fa fa-cog"></i> Settings </a> </li> <li> <a href="#"> <i class="ace-icon fa fa-user"></i> Profile </a> </li> <li class="divider"></li> <li> <a href="#"> <i class="ace-icon fa fa-power-off"></i> Logout </a> </li> </ul> </li> </ul> </div> </div> <!-- /.navbar-container --> </div> <div class="main-container" id="main-container"> <div id="sidebar" class="sidebar responsive"> <ul class="nav nav-list"> <li class="<?php echo $title == 'Home' ? 'active' : '' ?>"> <a href="/"> <i class="menu-icon fa fa-tachometer"></i> <span class="menu-text"> Dashboard </span> </a> <b class="arrow"></b> </li> <li class="<?php echo $title == 'about' ? 'active' : ''?>"> <a href="/about"> <i class="menu-icon fa fa-list-alt"></i> <span class="menu-text"> About us </span> </a> <b class="arrow"></b> </li> </ul> <!-- /.nav-list --> <div class="sidebar-toggle sidebar-collapse" id="sidebar-collapse"> <i class="ace-icon fa fa-angle-double-left" data-icon1="ace-icon fa fa-angle-double-left" data-icon2="ace-icon fa fa-angle-double-right"></i> </div> </div> <div class="main-content"> <div class="main-content-inner"> <div class="breadcrumbs" id="breadcrumbs"> <ul class="breadcrumb"> <li> <i class="ace-icon fa fa-home home-icon"></i> <a href="/">Home</a> </li> <?php if($title != 'Home') :?> <li class="active"><?php echo $title;?></li> <?php endif;?> </ul> <div class="nav-search" id="nav-search"> <form class="form-search"> <span class="input-icon"> <input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input1" autocomplete="off"> <i class="ace-icon fa fa-search nav-search-icon"></i> </span> </form> </div> </div> <div class="page-content"> <div class="row"> <div class="col-xs-12"> <!-- PAGE CONTENT BEGINS --> <?= $this--->renderSection('content') ?> <!-- PAGE CONTENT ENDS --> </div> <!-- /.col --> </div> <!-- /.row --> </div> <!-- /.page-content --> </div> </div> <!-- /.main-content --> <div class="footer"> <div class="footer-inner"> <div class="footer-content"> <span class="bigger-120"> Copyright � phpflow.com. All rights reserved. </span> </div> </div> </div> <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse"> <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i> </a> </div> <!-- /.main-container --> <!-- basic scripts --> <script type="text/javascript" src="<?php echo base_url(" js/jquery.min.js");?>"></script> <script src="<?php echo base_url("js/bootstrap.min.js");?="">"></script>
We have created a default layout file, Let’s create a handler method into this file, I am creating Home.php
file in the app/Controllers folder. Created a index()
method into it. Please add the below code into Home.php
controller file.
<?php namespace App\Controllers; class Home extends BaseController { public function index() { $data = array(); return view('home'); } }
We have defined the home view file path in index()
controller method. Now we will create a new home.php view file into Views/
folder. Please add the below code into this file,
<?= $this->extend('default_layout') ?> <?= $this->section('content') ?> Lorem Ipsum is .... Lorem Ipsum. <?= $this->endSection() ?>
Let’s create a new page in Codeigniter 4 tutorial, This page will have the same above custom page layout. Create an about page into /Views
folder, This page will render on the same page layout. We just send view to the Default Layout file and the rest of the theme structure same as the home.
Step 1: Create a new entry route into app/Routes.php
file.
$routes->get('/about', 'Home::about');
We have mentioned home
is controller and about
is a method.
Step 2: Created about method into Home.php
controller file.
public function about() { $data = array(); return view('about'); }
Step 3: Created about.php
view file into views
folder.
<?= $this->extend('default_layout') ?> <?= $this->section('content') ?> About page -Lorem Ipsum .... Lorem Ipsum. <?= $this->endSection() ?>
This is a Codeigniter beginners tutorial help to integrate a beautiful bootstrap theme with Codeigniter 4 using Layout. You can also integrate a simple HTML theme using this CodeIgniter tutorial. We have created a new controller and view file and rendered them using the template.
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More