CodeIgniter Helper
What is Helper
In CodeIgniter there are assistants which are there to assist you with various undertakings. Each aide document is an assortment of capacities pointing towards a specific job. A portion of the assistants are 'document aides' which help you to manage the record, 'content aides' to perform different content arranging schedules, 'structure aides' to make structure component, 'treat aides' set and understood treats, 'URL aides' which help with making joins, and so on.
Aides are not written in Object Oriented configuration, rather they are straightforward, procedural capacities, free of one another.
To utilize partner records, you have to stack it. When stacked it is all inclusive accessible to your controller and perspectives. They are situated at two places in CodeIgniter. CodeIgniter will search first for an aide in application/assistants envelope and in the event that not discovered there, at that point it will go to framework/partners organizer.
Loading a Helper
A partner can be stacked in controller constructor which makes them comprehensively accessible, or they can likewise be stacked in explicit capacities which need them.
It very well may be stacked with the accompanying code:
$this->load->helper('file_name');
Compose your record name here at the spot of file_name.
To stack URL aide,
$this->load->helper('url');
You can likewise auto-load a partner if your application needs that aide all inclusive by including the assistant in application/config/autoload.php record.
Loading Multiple Helpers
To stack numerous assistants, indicate them in a cluster,
this->load->helper(
array('helper1', 'helper2', 'helper3')
);
html Helper Example
We are going to show you a case of html partner by utilizing it in a fundamental site page. Here, we'll auto-load our partner.
Go to autoload.php document by means of utilization/config/autoload.php
$autoload['helper'] = array('html');
In the above document, name your aide, here it is html.
In application/controllers there is document Form.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Form extends CI_Controller {
public function index()
{
$this->load->view('header');
$this->load->view('nav');
$this->load->view('content');
$this->load->view('footer');
}
}
?>
In application/sees there is document header.php
The main line is coded in php tag.
<?php echo doctype("html5"); ?>
<html>
<head>
<title>Basic Site</title>
<style type="text/css">
body, html{margin:0; padding:0;}
body{
background-color:#eee;
}
h1, h2, h3, h4, p, a, li, ul{
font-family: arial, sans-serif;
color: black;
text-decoration: none;
}
#nav{
margin: 50px auto 0 auto;
width: 10000px;
background-color: #888;
height: 15px;
padding: 20px;
}
#nav a:hover{
color: red;
}
#nav ul{
list-style: none;
float: left;
margin: 0 50px;
}
#nav ul li{
display: inline;
}
#content{
width: 1000px;
min-height: 100%;
margin: 0 auto;
padding: 20px;
}
#footer{
width: 400px;
height: 15px;
margin: 0 auto;
padding: 20px;
}
#footer p{
color: #777;
}
</style>
</head>
The other half coding for record header.php is appeared in beneath preview.
In application/sees there is document content.php
Here additionally the heading is written in php tag rather than html.
<div id="content">
<?php echo heading("Welcome to my site", 1); ?>
<p>In a professional context it often happens that private or corporate clients
corder a publication to be made and presented with the actual content still not being ready.
Think of a news blog that's filled with content hourly on the day of going live. However,
reviewers tend to be distracted by comprehensible content, say, a random text copied from
a newspaper or the internet. The are likely to focus on the text, disregarding the layout
and its elements. Besides, random text risks to be unintendedly humorous or offensive,
an unacceptable risk in corporate environments.</p>
</div>
Last yield is much the same as an ordinary page as appeared underneath with the URL localhost/assistant/index.php/Form.
Be that as it may, when we will see its open source (by squeezing ctrl+u), you will see the accompanying coding which essentially shows html code and not php code what we have composed previously.
