আগামী ৩০ অক্টোবর -২০১৭ তারিখ থেকে শুরু হচ্ছে পাঁচ মাস ব্যাপী Professional Web Design and Development with HTML,CSS,Bootstrap,PHP,MySQl, AJAX and JQUERY কোর্সের ৮৬ তম ব্যাচ। আগ্রহীদেরকে অতিসত্বর মাসুদ আলম স্যার এর সাথে যোগাযোগ করতে অনুরোধ করা যাচ্ছে। স্যার এর মোবাইল: 01722817591, Email : [email protected] কোর্সের সিলেবাস এর জন্য এখানে ক্লিক করুন ।

An Overview of CodeIgniter Helper and Libraries

CodeIgniter-logoCodeIgniter provides two types of facilities that can be used to assist in the development of applications, including:

Library

Library can be considered as a collection of tools that can be used to assist the process. CodeIgniter has provided a lot of libraries that can be used mainly directly. Library is essentially a class that is placed in the folder system / libraries or application / libraries. Library located in the system folder is a default library of CodeIgniter that by default in the given prefix CI_. For homemade library should be placed in the folder application / libraries

Helper

Helper is a collection of functions placed in the folder system / helpers or applications / helpers. Usually helper is often used in a view to assist the processes are repeated, separti generate html, url, security, etc.

Using the Library and Helper in CodeIgniter

In order to use the library, helper and pluggin, then three must be loaded first. There are two ways you can do to download and load a helper library include:

1. Adding the Autoload Configuration

Adding an autoload library in the entire application means you’ll be able to use the library directly. Should library that is loaded in this way is a kind of library that is used across applications such as logging, templates, etc.

2. Using the Command Loader Library

We may also use the library loader to download the load library. Library loader is a library CodeIgniter are automatically loaded. Loader functions as a regulator of the resources available In CodeIgnier as Model, View, Library, Helper, and pluggin. How to use is:

 $ this-> load-> library ('name_library');
 $ this-> load-> helper ('name_helper');
 $ this-> load-> pluggin ('name_pluggin');
 

Name of the library, helper and pluggin must be filled with small letters. when a library is loaded in the library is a property of the object Controller.
As for how to use are as follows:

 $ this-> name_library-> function ();
 

CodeIgniter Library
By default CodeIgniter has provided a library that can be used directly. As for the library that are available include:

* Benchmarking Class

Library is used to measure the application made. Like to know how long execution time and the amount of memory used. This library is used and loaded automatically by CodeIgniter.

* Calendar Class
Library serves to display and generate the calendar

* Cart Class
Library serves to create a shopping cart (shopping cart). Library has dependence on the class session for chart items are stored in the session

* Config Class
This library function to retrieve the data in the configuration file. This library is loaded automatically by CodeIgniter.

* Database Class
Library databases are used to manipulate and obtain data from a database system. By default database that is supported by CodeIgniter is MySQL, MSSQL, Oracle, Postgres, while databases that are not supported directly by CodeIgniter can bridged with odbc dirver.

* Email Class
Library e-mail is used to send email. Sending email can be done by using a protocol mail, sendmail and smtp.sqawd

* Encryption Class

Library Encryption is used to perform a particular string encoding terdadap

* File Uploading Class
Uploading Library is used to upload files. This class is equipped with checking file type, and file size.

* Form Validation Class
Library Validation form is used to check the validity of the forms that is submitted by the user

 

* FTP Class
Library FTP is used to upload or download files via ftp server.

* HTML Table Class
Library HTML table is a class that serves to generate the table of the data array

* Image Manipulation Class
Library image manipulation functions for image processing. The functions that have been provided is Image Resizing, Thumbnail Creation, Image Cropping, Image Rotating and Image Watermarking

* Input and Security Class
Library Input and security functions to ensure that the input from the form was clear of the characters ‘odd’.

* Class Loader
This library can be called a resource manager CodeIgniter. All available resources will be controlled this class. Library is already loaded automatically by CodeIgniter.

* Language Class
Library language is used to set the language that will be used by CodeIgniter.

* Output Class
Output Library aims to handle output from CodeIgniter, ranging from the cache to the profiling this class can be done.

* Pagination Clsass
For paginate database results on performance and usability, we can control how many records to display every page of the website, how many records to be withdrawn from from the database and display pagination

* Session Class
Library Session can be used to maintain state information about the user (like session separti in PHP). But the library is not using the built-in session from PHP, Library Session to generate its own data session Cookies are stored in the.

* Trackback Class

Trackback Library is used to send and receive data trackback.

* Template Parser Class
Library Template Parser is used to create a template that contains parsable pseudo templates.

* Unit Testing Class

Unit Testing Library used to unit test function in the application being made. CodeIgniter provides evaluation function and two functions results in this library.

* URI Class
Library URI is used for parsing the URL, and then breaking it down into several segments and then passed to the controller or stored as a variable.

* User Agent Class

Library User Agent is used to identify the browser, mobile device, visit the website or in the robot. We can also use it to detect support for languages, character sets, and referrer.

* XML-RPC Class
XML-RPC library used to setup the XML-RPC client and server.

* Zip Encoding Class
Zip Encoding Library is used to create a ZIP file either text or binary data type

Helper CodeIgniter

Helpers like the name suggests will help you build an application with a specific task. Unlike a library, not a helper Object Oriented but procedural form. Each helper contains one or more functions, each focusing on a specific task that no dependence with other functions

Helper can also be loaded automatically in the / system / application / config / autload.php. The helper is in CodeIgniter, among others

* Array: helper array contains functions that assist the work associated with the array. For example random_element function () takes an array as input and generates a random element from it.

* Cookie:  cookie-Helper contains functions that assist the work related to the provision of value, data reading cookies and cookie data deletion.

* Data-Helper: data contains functions that assist the work associated with the date. for example, the function now () returns the current time as a Unix timestamp.

* Directory: Helper directory contains a single function that helps job bergubungan the directory. As example directory_map function () is to read the specified directory path and build its array containing all the files and subdirectories
* Download: Helper download contains a single function that helps to download data with ease. Force_download function () generates a server header which forces the data to be downloaded

* File: Helper file contains functions that help to read, write, and delete files

* Form Helper form contains functions that help build the form

* HTML: Helper HTML contains functions that help make the HTML block quickly and easily. For example, the function ul () can change the array item to the bulleted list

* Inflector:  inflector helper contains functions that help transform the words into the plural or singular,imposing camel case or change the words separated by spaces into an underlined phrase, for example, can alter the function of singular string ‘girls’ to ‘girl’

* Security:  Security Helper contains security-related functions such as xss_clean (), which will filter out any codes that may be used in cross-site scripting hack

* Smiley:  smiley Helper contains functions that help manage emoticons.

* String:  String Helper contains functions that will make a random string based on the type and length of arguments

* Text:  Helper text contains functions that help you work with text. For example: word_limiter function, can limit the string to a certain number of words that are useful to restrict user input on the form.

* Typography:  typography Helper ferisi single function that helps format the text in an appropriate manner.For example: auto_typography function () wraps with <p> paragraph and </ p>, convert line breaks into <br/> and convert quotes, dash, and ellipse well.

* URL:  Helpler URL contains functions that help working with URLs. You will use the base_url () and anchor () in each project.

*XML:  XML Helper Beris single function that helps to work with XML. Xml_convert function serves to convert a text string into XML, convert ampersand and angle brackets into entities.

Creating Your Own Library

To get a good code should be the same functionality is wrapped into a library.A library is a class that is placed in the folder application / libraries

Get_instance () is a function that implements the singleton from the CI controller. If you create a library themselves and require data or other resources contained in the main object, we can use function to access data or resources required.

As an example we will create a library that will utilize breadcrumb layout of URI segments. Data can be accessed from the library URI uri already be loaded automatically by CodeIgniter.

 

Using External Library
CodeIgniter is very easy to adopt a library that is external. Library of the easiest to adopt is a single class without parameter the constructor. For classes that have more than one constructor it should the first amended class or if the class library is made up on some more makeup class we easily create a library the library’s factory

Using External Library

CodeIgniter is very easy to adopt a library that is external. Library of the easiest to adopt is a single class without parameter the constructor. For classes that have more than one constructor it should The first amended class or if the class library consists of several class makeup more easily we create a library The library’s factory

Example 1. CSV Reader Library

As an example we will use a library function to read CSV file into memory. The contents of the library are

 <?php

if(!defined('BASEPATH')){

exit('No direct script access allowed');

}

class csv_reader{

public $fields;

public $separator=';';

public $enclosure='"';

public $max_row_size=4096;

function parse_file($p_Filepath, $p_NameFields=true){

$content=false;

$file=fopen($p_Filepath,'r');

if($p_NamedFields){

$this->fields=fgetcsv($file,$this->max_row_size,

$this->separator,$this->enclosure);

}

while(($row=fgetcsv($file,$this->max_row_size,$this->separator,$this->enclosure))!=false){

if($row[0]!=null){

//skip empty lines

if(!$content){

$content=array();

}

if($p_NamedFields){

$items=array();

foreach($this->fields as $id=>$field){

if(isset($row[$id])){

$items[$field]=$row[$id];

}

}

$content[]=$items;

}

else{

$content[]=$row;

}

}

}

fclose($file);

return $content;

}

}
 

In order to use the library should take the following steps:

Copy to Directory Library application / libraries

to use the library of our own or external library then the first step that must be done library is putting it in the directory application / libraries. The file name and class name must be the same. Examples of file names is csv_reader.php. Hence the name of the class is csv_reader

Load Loader Library Using the Library

After putting the library in the directory application / libraries we live load library or classroom them. Once loaded, the name of the library will be a property in the controller class.

Consider the following Controller

 <?php

if(!defined('BASEPATH')){

exit('No direct script access allowed');

}

class Welcome extends CI_Controller{

function __construct(){

parent::__construct();

}

function index(){

$this->load->library('csv_reader');

$data=$this->csv_reader->parse_file(FCPATH.'data_value.csv');

echo"<pre>";

print_r($data);

}

}

/* End of file welcome.php */

/* Location ./application/controllers/welcome.php

?>
 

on line 13 we will try to use the library csv_reader, classes will be parsing a CSV file. Then we show the results parsingan in your browser screen

The Contents of the data_value.csv File are:

"Yakub Mizan","Mamun Haque","Shishir Chakrabarty","Salim Hossain","Kawser Ahmed"

"Fahad Billah","BulBul Mahmud Nito","Vimrul","Fatema khatun","Zakir Hossain"

Now run your CI and see sample output 🙂
CSV Reader With CodeIgniter

Hi, My name is Masud Alam, love to work with Open Source Technologies, living in Dhaka, Bangladesh. I graduated in 2009 with a bachelor's degree in Engineering from State University Of Bangladesh, I'm also a Certified Engineer on ZEND PHP 5.3, I served my first five years a number of leadership positions at Winux Soft Ltd, SSL Wireless Ltd, CIDA and MAX Group where I worked on ERP software and web development., but now i'm a co-founder and Chief Executive Officer and Managing Director of TechBeeo Software Consultancy Services Ltd. I'm also a Course Instructor of ZCPE PHP 7 Certification and professional web development course at w3programmers Training Institute - a leading Training Institute in the country.
2 comments on “An Overview of CodeIgniter Helper and Libraries

Leave a Reply

Your email address will not be published. Required fields are marked *