Codeigniter Tutorials
- What is codeigniter?
- Application_Architecture
- MVC Architecture
- HMVC Architecture
- Codeigniter Configuration
- Remove index.php from url in codeigniter
- MVC Concept
- View
- Alternate PHP Syntax for View Files
- Routing
- Codeigniter URL
- Get Current URL
- Previous page URL get
- Seo Friendly URL
- Slug Create in codeigniter
- What is _remap() function
- Remove controller name from url in codeigniter
- Codeigniter Controller Class
- Class Constructor
- GET $ POST method in Codeigniter
- Models
- Basepath, Apppath, FCPATH
- URI Segment
- Page Redirect
- Helper class
- Custom Helper class
- Form Helper
- Common Helper Functions
- Common Function
- Array Problems
- Call controller in Helper
- Add active class to menu using Helper class
- Custom Library
- Custom Library Example
- when to use get_instance()
- Codeigniter Hook
- how to work inline css in codeigniter
- Custom 404 page
- 404 custom error page
- Create custom config file in codeigniter
- How to set and get config item value
- How to Speed Up CodeIgniter App?
- Codeigniter Functions
- Session
- cookies
- How to Set & Get Tempdata in Codeigniter
- flash messages in Codeigniter
- Flashdata
- Encryption and Decryption In CodeIgniter
- Codeigniter security
- csrf token form security
- Password Hashing
- Form Validation
- Custom Validation
- Registration Form with validation
- Server Side Form Validation
- Validate Select Option Field
- Date Format Validation
- Date Format change in codeigniter
- Date Functions
- DOB Validation
- CI CRUD
- User SignUp
- User Login
- User Logout
- Login Account
- Login form with RememberMe
- Login Form with session
- User change password
- Change Password with Callback Validation to Check Old Password
- Forgot password
- Reset password
- Insert data in database
- Fetch data from database
- Update data in database
- Delete data in database
- File Upload
- Image Upload with resize Image
- Upload Multiple file and images
- Upload Multiple images with CRUD
- File and image update
- Upload Image Using Ajax.
- Email Send
- Email Send Using Email library
- Email Send Using SMTP Gmail
- Notification send
- store data in json format in DB
- Json parse
- Fetch data Using Ajax with Json data
- How to Show data Using Ajax with Json parse
- Get JSON Data from PHP Script using jQuery Ajax
- Insert data Using Ajax
- Submit data Using Ajax with form validation
- How to show data Using Ajax in codeigniter
- Insert & Update Using Ajax
- Registration Form With Validation Using Ajax in codeigniter
- Delete data Using Ajax Confirmation
- Delete All data Using checkbox selection
- Ajax CSRF Token
- Ajax Post
- Ajax serverside form validation
- Contact form using AJAX with form validation
- DataTable Using Ajax dynamically
- DataTables pagination using AJAX with Custom filter
- DataTables AJAX Pagination with Search and Sort in codeigniter
- DataTables in Codeigniter using Ajax
- Ajax Custom Serarch
- Ajax Live Data Search using Jquery PHP MySql
- Ajax Custom Serarch and sorting in datatable
- Dynamic Search Using Ajax
- Autocomplete using jquery ajax
- Jquery Ajax Autocomplete Search using Typeahead
- Dynamic Dependent Dropdown Using Ajax
- Dynamic Dependent Dropdown list Using Ajax
- Dynamic Dependent Dropdown in codeigniter using Ajax
- ajax username/email availability check using JQuery
- Check Email Availability Using Ajax
- Data Load on mouse scroll
- Ajax CI Pagination
- Pagination in codeigniter
- Ajax Codeigniter Pagination
- email exists or not using ajax with json
- CRUD using AJAX With Modal popup in CI
- Add / Show Data on modal popup using Ajax
- Modal popup Validation using Ajax
- Data show on Modal popup Using Ajax
- Add / Remove text field dynamically using jquery ajax
- How to Add/Delete Multiple HTML Rows using JavaScript
- Delete Multiple Rows using Checkbox
- Multiple Checkbox value
- Form submit using jquery Example
- REST & SOAP API
- Multi-Language implementation in CodeIgniter
- How to pass multiple array in view
- Captcha
- create zip file and download
- PhpOffice PhpSpreadsheet Library (Export data in excel sheet)
- data export in excel sheet
- Excel File generate in Codeigniter using PHPExcel
- Dompdf library
- tcpdf library
- Html table to Excel & docs download
- CI Database Query
- Database Query
- SQL Injection Prevention
- Auth Model
- Join Mysql
- Tree View in dropdown option list
- OTP Integration in codeigniter
- curl post
- download file using curl
- Sweet Alert
- Sweet alert Delete & Success
- Log Message in Codeigniter
- Menu & Submenu show dynamically
- Set Default value in input box
- Cron Jobs
- Stored Procedure
- Display Loading Image when AJAX call is in Progress
- Send SMS
- IP Address
- Codeigniter Tutorialspoint
- Website Link
- How To Create Dynamic Xml Sitemap In Codeigniter
- Paypal Payment Integration
- Get Latitude and Longitude From Address in Codeigniter Using google map API
- How To Create Simple Bar Chart In Codeigniter Using AmCharts?
- dynamic Highcharts in Codeigniter
- Barcode in Codeigniter
- Codeigniter Interview Questions
- Project
How to Load a view in codeigniter?
load a view in CodeIgniter, we use the built in Loader library.
File name :
$this->load->view('itechxpert', $data, true/false);
$this->load->view will tell CodeIgniter to look for itechxpert.php in the application/views directory, and display the contents of the file on the browser.
Note:
The CodeIgniter allows you to exclude the .php suffix from the view page.
File name :
The second parameter $data is optional and takes an associative array or object. This array/object is used to pass data to the view file, so it can be used or referenced within the view.
The final optional parameter determines whether the view's contents is displayed in the browser window, or returned as a string. This parameter defaults to false, displaying the content in the browser.
How to use view in codeigniter?
in CodeIgniter when a user requests something data from the browser then request goes to the codeigniter controller, controller process Your logic and controller handles the request and sends result to the view. The view is webpage which includes the HTML, CSS and PHP code.
your controller class handle the logic to get the data from the database and finally show the data on the view page.
File name :
Pass Data from codeigniter Controller to View.
1. First Create a View
2. Load the View
3. Pass data array from the controller to view.
4. you can Load Multiple Views
5. Load View from Sub directory
6. Add Dynamic Data to Views
7. Returning View as Data
First Create a View
File name : index.php
<html>
<head>
<title>Welcome itechxpert</title>
</head>
<body>
<h1>Codeigniter View</h1>
</body>
</html>
Load the View
File name :
$this->load->view('index');
// here index is the name of your view page. such as index.php
Controller
File name : Itechxpert.php
<?php
class Itechxpert extends CI_Controller {
public function index() {
$this->load->view('index');
}
}
?>
Pass array from the controller to view and display on view
File name : Itechxpert.php
<?php
class Itechxpert extends CI_Controller {
public function index() {
$data['page_details'] = array("title" => "itechxpert", "heading" => "Home Page");
$this->load->view('index', $data);
}
}
?>
show data on view page
we have the array page_details which holds the details. and added the second argument to the load view, load view takes the first argument as the name of the view, the second argument is the data which we send from the controller to the view.
File name :
<html>
<head>
<title><?php echo $page_details['title']; ?></title>
</head>
<body>
<h1><?php echo $page_details['heading']; ?> </h1>
</body>
</html>
Load Multiple Views
File name :
<?php
class Itechxpert extends CI_Controller {
public function index() {
$data['page_details'] = array("title" => "itechxpert", "heading" => "Rahatfoundation");
$this->load->view('header');
$this->load->view('sidebar');
$this->load->view('index', $data);
$this->load->view('footer');
}
}
Load View from Sub Directory
File name :
<?php
class Itechxpert extends CI_Controller {
public function index() {
$data['page_details'] = array("title" => "itechxpert", "heading" => "Home Page");
$this->load->view('pages/index', $data);
}
}
Add Dynamic Data to Views
File name :
<?php
class Itechxpert extends CI_Controller {
public function index() {
$data['page_details'] = array("title" => "itechxpert", "heading" => "Home page");
$data['user_details']=$this->Auth_model->get_user_details(); //This function returns the result array from the database
$this->load->view('pages/index', $data);
}
}
View page
File name : index.php
<html>
<head>
<title><?php echo $page_details['title']; ?></title>
</head>
<body>
<h1><?php echo $page_details['heading']; ?> </h1>
<table>
<thead>
<th>S.No</th>
<th>Name</th>
<th>Email</th>
<th>Mobile No.</th>
<th>Status</th>
</thead>
<tbody>
<?php
if (isset($user_details) && !empty($user_details)) {
$count = 1;
foreach ($user_details as $user) {
?>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo $user['name']; ?></td>
<td><?php echo $user['email']; ?></td>
<td><?php echo $user['mobile_no']; ?></td>
<td><?php echo $user['status']; ?></td>
</tr>
<?php
$count++; }
} else {
?>
<tr><td colspan="4">No Data found.</td></tr>
<?php } ?>
</tbody>
</table>
</body>
</html>
Returning View as Data
$this->load->view(); method third optional parameter decides to load the view as a data, basically, this is used when you want to store view as a data.
File name :
<?php
class Itechxpert extends CI_Controller {
public function index() {
$data['page_details'] = array("title" => "Itechxpert", "heading" => "This is heading");
$page = $this->load->view('pages/index', $data, true);
}
}
Show data on view page
File name :
<html>
<head>
<title><?php echo $page_details['title']; ?></title>
</head>
<body>
<h1><?php echo $page_details['heading']; ?> </h1>
<table>
<thead>
<th>Name</th>
<th>Email</th>
<th>Mobile No.</th>
<th>Status</th>
</thead>
<tbody>
<?php
if (isset($user_details) && !empty($user_details)) {
$count = 1;
foreach ($user_details as $user) {
?>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo $user->name; ?></td>
<td><?php echo $user->email; ?></td>
<td><?php echo $user->mobile_no; ?></td>
<td><?php echo $user->status; ?></td>
</tr>
<?php
$count++;}
} else {
?>
<tr><td colspan="4">No Data found.</td></tr>
<?php } ?>
</tbody>
</table>
</body>
</html>
File name :
File name :
Header
File name : header.php
<html lang="en">
<head>
<!-- SITE TITTLE -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BIGBAG Store - Ecommerce Bootstrap Template</title>
<!-- <?php //echo base_url('assets/css/bootstrap.css');?> -->
<!-- PLUGINS CSS STYLE -->
<link href="<?php echo base_url('assets/plugins/jquery-ui/jquery-ui.css');?>" rel="stylesheet">
<link href="<?php echo base_url('assets/plugins/bootstrap/css/bootstrap.min.css');?>" rel="stylesheet">
<link href="<?php echo base_url('assets/plugins/font-awesome/css/font-awesome.min.css');?>" rel="stylesheet">
<link href="<?php echo base_url('assets/plugins/selectbox/select_option1.css');?>" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/plugins/rs-plugin/css/settings.css');?>" media="screen">
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/plugins/owl-carousel/owl.carousel.css');?>" media="screen">
<link rel="stylesheet" href="<?php echo base_url('assets/options/optionswitch.css');?>">
<link href='https://fonts.googleapis.com/css?family=Oxygen:400,300,700' rel='stylesheet' type='text/css'>
<link href="<?php echo base_url('assets/css/style.css');?>" rel="stylesheet">
<link rel="stylesheet" href="<?php echo base_url('assets/css/colors/default.css');?>" id="option_color">
</head>
<body>
Index
File name : index.php
<?php include 'header.php'; ?>
<!-- BANNER -->
<div class="bannercontainer">
<div class="fullscreenbanner-container">
<div class="fullscreenbanner">
<ul>
<li data-transition="slidehorizontal" data-slotamount="5" data-masterspeed="700" data-title="Slide 1">
<img src="img/home/banner-slider/slider-bg.jpg" alt="slidebg1" data-bgfit="cover" data-bgposition="center center" data-bgrepeat="no-repeat">
<div class="slider-caption container">
<div class="tp-caption rs-caption-1 sft start"
data-hoffset="0"
data-x="370"
data-y="54"
data-speed="800"
data-start="1500"
data-easing="Back.easeInOut"
data-endspeed="300">
<img src="img/home/banner-slider/shoe1.png" alt="slider-image">
</div>
<div class="tp-caption rs-caption-2 sft"
data-hoffset="0"
data-y="119"
data-speed="800"
data-start="2000"
data-easing="Back.easeInOut"
data-endspeed="300">
Canvas Sneaker
</div>
<div class="tp-caption rs-caption-3 sft"
data-hoffset="0"
data-y="185"
data-speed="1000"
data-start="3000"
data-easing="Power4.easeOut"
data-endspeed="300"
data-endeasing="Power1.easeIn"
data-captionhidden="off">
Exclusive to <br>
BigBag <br>
<small>Spring / Summer 2016</small>
</div>
<div class="tp-caption rs-caption-4 sft"
data-hoffset="0"
data-y="320"
data-speed="800"
data-start="3500"
data-easing="Power4.easeOut"
data-endspeed="300"
data-endeasing="Power1.easeIn"
data-captionhidden="off">
<span class="page-scroll"><a target="_blank" href="http://goo.gl/VCbeOp" class="btn primary-btn">Buy Now<i class="glyphicon glyphicon-chevron-right"></i></a></span>
</div>
</div>
</li>
<li data-transition="slidehorizontal" data-slotamount="5" data-masterspeed="1000" data-title="Slide 2">
<img src="img/home/banner-slider/slider-bg.jpg" alt="slidebg" data-bgfit="cover" data-bgposition="center center" data-bgrepeat="no-repeat">
<div class="slider-caption container captionCenter">
<div class="tp-caption rs-caption-1 sft start captionCenterAlign"
data-x="center"
data-y="228"
data-speed="800"
data-start="1500"
data-easing="Back.easeInOut"
data-endspeed="300">
<img src="img/home/banner-slider/shoe2.png" alt="slider-image">
</div>
<div class="tp-caption rs-caption-2 sft captionCenterAlign"
data-x="center"
data-y="50"
data-speed="800"
data-start="2000"
data-easing="Back.easeInOut"
data-endspeed="300">
Exclusive to BigBag
</div>
<div class="tp-caption rs-caption-3 sft captionCenterAlign"
data-x="center"
data-y="98"
data-speed="1000"
data-start="3000"
data-easing="Power4.easeOut"
data-endspeed="300"
data-endeasing="Power1.easeIn"
data-captionhidden="off">
Canvas Sneaker
</div>
<div class="tp-caption rs-caption-4 sft captionCenterAlign"
data-x="center"
data-y="156"
data-speed="800"
data-start="3500"
data-easing="Power4.easeOut"
data-endspeed="300"
data-endeasing="Power1.easeIn"
data-captionhidden="off">
<span class="page-scroll"><a target="_blank" href="http://goo.gl/VCbeOp" class="btn primary-btn">Buy Now<i class="glyphicon glyphicon-chevron-right"></i></a></span>
</div>
</div>
</li>
<li data-transition="slidehorizontal" data-slotamount="5" data-masterspeed="700" data-title="Slide 3">
<img src="img/home/banner-slider/slider-bg.jpg" alt="slidebg" data-bgfit="cover" data-bgposition="center center" data-bgrepeat="no-repeat">
<div class="slider-caption container">
<div class="tp-caption rs-caption-1 sft start"
data-hoffset="0"
data-x="0"
data-y="85"
data-speed="800"
data-start="1500"
data-easing="Back.easeInOut"
data-endspeed="300">
<img src="img/home/banner-slider/shoe3.png" alt="slider-image">
</div>
<div class="tp-caption rs-caption-2 sft "
data-hoffset="0"
data-y="119"
data-x="800"
data-speed="800"
data-start="2000"
data-easing="Back.easeInOut"
data-endspeed="300">
Canvas Sneaker
</div>
<div class="tp-caption rs-caption-3 sft"
data-hoffset="0"
data-y="185"
data-x="800"
data-speed="1000"
data-start="3000"
data-easing="Power4.easeOut"
data-endspeed="300"
data-endeasing="Power1.easeIn"
data-captionhidden="off">
Exclusive to <br>
BigBag <br>
<small>Spring / Summer 2016</small>
</div>
<div class="tp-caption rs-caption-4 sft"
data-hoffset="0"
data-y="320"
data-x="800"
data-speed="800"
data-start="3500"
data-easing="Power4.easeOut"
data-endspeed="300"
data-endeasing="Power1.easeIn"
data-captionhidden="off">
<span class="page-scroll"><a target="_blank" href="http://goo.gl/VCbeOp" class="btn primary-btn">Buy Now<i class="glyphicon glyphicon-chevron-right"></i></a></span>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<?php include 'footer.php'; ?>
Footer
File name : footer.php
<script src="<?php echo base_url();?>assets/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="<?php echo base_url();?>assets/plugins/jquery-ui/jquery-ui.js"></script>
<script src="<?php echo base_url();?>assets/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="<?php echo base_url();?>assets/plugins/rs-plugin/js/jquery.themepunch.tools.min.js"></script>
<script src="<?php echo base_url();?>assets/plugins/rs-plugin/js/jquery.themepunch.revolution.min.js"></script>
<script src="<?php echo base_url();?>assets/plugins/owl-carousel/owl.carousel.js"></script>
<script src="<?php echo base_url();?>assets/plugins/selectbox/jquery.selectbox-0.1.3.min.js"></script>
<script src="<?php echo base_url();?>assets/plugins/countdown/jquery.syotimer.js"></script>
<script src="<?php echo base_url();?>assets/options/optionswitcher.js"></script>
<script src="<?php echo base_url();?>assets/js/custom.js"></script>
</body>
</html>
Header
File name : header.php
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Starhotel</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="shortcut icon" href="favicon.ico">
<base href="<?php echo base_url();?>">
<link rel="stylesheet" href="assets/css/animate.css">
<link rel="stylesheet" href="assets/css/bootstrap.css">
<link rel="stylesheet" href="assets/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/owl.carousel.css">
<link rel="stylesheet" href="assets/css/owl.theme.css">
<link rel="stylesheet" href="assets/css/prettyPhoto.css">
<link rel="stylesheet" href="assets/css/smoothness/jquery-ui-1.10.4.custom.min.css">
<link rel="stylesheet" href="assets/rs-plugin/css/settings.css">
<link rel="stylesheet" href="assets/css/theme.css">
<link rel="stylesheet" href="assets/css/colors/turquoise.css" id="switch_style">
<link rel="stylesheet" href="assets/css/responsive.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600,700">
<!-- Javascripts -->
<script type="text/javascript" src="assets/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/bootstrap-hover-dropdown.min.js"></script>
<script type="text/javascript" src="assets/js/owl.carousel.min.js"></script>
<script type="text/javascript" src="assets/js/jquery.parallax-1.1.3.js"></script>
<script type="text/javascript" src="assets/js/jquery.nicescroll.js"></script>
<script type="text/javascript" src="assets/js/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="assets/js/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript" src="assets/js/jquery.forms.js"></script>
<script type="text/javascript" src="assets/js/jquery.sticky.js"></script>
<script type="text/javascript" src="assets/js/waypoints.min.js"></script>
<script type="text/javascript" src="assets/js/jquery.isotope.min.js"></script>
<script type="text/javascript" src="assets/js/jquery.gmap.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="assets/rs-plugin/js/jquery.themepunch.tools.min.js"></script>
<script type="text/javascript" src="assets/rs-plugin/js/jquery.themepunch.revolution.min.js"></script>
<script type="text/javascript" src="assets/js/switch.js"></script>
<script type="text/javascript" src="assets/js/custom.js"></script>
How to Load Multiple Views in single View in CodeIgniter?
File name : Controller :- User.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User extends CI_Controller {
public function __construct() {
parent::__construct();
// load base_url
$this->load->helper('url');
}
public function index(){
$data['content'] = "Home Page";
// load view
$this->load->view('header_view');
$this->load->view('home_view',$data);
$this->load->view('footer_view');
}
}
You can also load view in another view page.
Header view
File name : header_view.php
<!doctype html>
<html>
<head>
<style>
/* Menu */
.menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: darkturquoise;
}
.menu li {
float: left;
}
.menu li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.menu li ul{
display: none;
}
.menu li a:hover {
background-color: #2b90f5;
}
.active{
background: #2b90f5;
}
footer{
bottom: 0;
position: absolute;
border-top: 1px solid gray;
width: 98%;
padding: 20px 0px;
text-align: center;
}
</style>
</head>
<body>
<ul class='menu'>
<li><a href="<?= site_url() ?>">Home</a></li>
<li><a href="#">Aboutus</a></li>
</ul>
Footer view
File name : footer_view.php
<footer>
Copywrite © <?php echo date('Y'); ?>
</footer>
</body>
</html>
File name :
<?php
// Load header_view
$this->load->view('header_view');
?>
<h2><?= $content; ?></h2>
<table>
<tr>
<td>Name : </td>
<td><input type='text' /></td>
</tr>
<tr>
<td>Username : </td>
<td><input type='text' /></td>
</tr>
<tr>
<td>Email : </td>
<td><input type='text' /></td>
</tr>
<tr>
<td> </td>
<td><input type='button' value='Submit' /></td>
</tr>
</table>
<?php
// Load footer_view
$this->load->view('footer_view');
?>
File name :
File name :
File name :