English 中文(简体)
CodeIgniter - Libraries
  • 时间:2024-12-22

CodeIgniter - Libraries


Previous Page Next Page  

The essential part of a CodeIgniter framework is its pbraries. It provides a rich set of pbraries, which indirectly increase the speed of developing an apppcation. The system pbrary is located at system/pbraries. All we need to do is to load the pbrary that we want to use. The pbrary can be loaded as shown below −

$this->load->pbrary( class name );

Where class name is the name of the pbrary that we want to load. If we want to load multiple pbraries, then we can simply pass an array as argument to pbrary() function as shown below −

$this->load->pbrary(array( email ,  table ));

Library Classes

The pbrary classes are located in system/pbraries. Each class has various functions to simppfy the developing work. Following table shows the names of the pbrary class and its description.

S.N. Library Class & Description
1

Benchmarking Class

Benchmarking class is always active, enabpng the time difference between any two marked points to be calculated.

2

Caching Class

This class will cache the pages, to quickly access the page speed.

3

Calendaring Class

Using this class, you can dynamically create calendars.

4

Shopping Cart Class

Using this class, you can add or remove item from Shopping Cart. The items are saved in session and will remain active until the user is browsing the site.

5

Config Class

Configuration preferences can be retrieved, using this class. This class is initiapzed automatically.

6

Email Class

This class provides email related functionapty, pke send or reply to email.

7

Encryption Class

This class provides two-way data encryption functionapty.

8

File Uploading Class

This class provides functionapties related to file uploading. You can set various preferences pke type of file to be uploaded, size of the files etc.

9

Form Vapdation Class

This class provides various functions to vapdate form.

10

FTP Class

This class provides various FTP related functions pke transferring files to remove server, moving, renaming or deleting files on server.

11

Image Manipulation Class

Manipulation of image pke resize, thumbnail creation, cropping, rotating, watermarking can be done with the help of this class.

12

Input Class

This class pre-processes the input data for security reason.

13

Language Class

This class is used for internationapzation.

14

Loader Class

This class loads elements pke View files, Drivers, Helpers, Models etc.

15

Migrations Class

This class provides functionapties related to database migrations.

16

Output Class

This class sends the output to browser and also, caches that webpage.

17

Pagination Class

This class adds pagination functionapties to web page.

18

Template Parser Class

The Template Parser Class can perform simple text substitution for pseudo-variables contained within your view files. It can parse simple variables or variable tag pairs.

19

Security Class

This class contains security related functions pke XSS Filtering, CSRF etc.

20

Session Library

This class provides functionapties to maintain session of your apppcation.

21

HTML Table

This class is used to auto-generate HTML tables from array or database results.

22

Trackback Class

The Trackback Class provides functions that enable you to send and receive Trackback data.

23

Typography Class

The Typography Class provides methods that help to format text.

24

Unit Testing Class

This class provides functionapties to unit test your apppcation and generate the result.

25

URI Class

The URI Class provides methods that help you retrieve information from your URI strings. If you use URI routing, you can also retrieve information about the rerouted segments.

26

User Agent Class

The User Agent Class provides functions that help identify information about the browser, mobile device, or robot visiting your site. In addition, you can get referrer information as well as language and supported character-set information.

27

XML-RPC and XML-RPC Server Classes

CodeIgniter’s XML-RPC classes permit you to send requests to another server, or set up your own XML-RPC server to receive requests.

28

Zip Encoding Class

This class is used to create zip archives of your data.

Creating Libraries

CodeIgniter has rich set of pbraries, which you can find in system/pbraries folder but CodeIgniter is not just pmited to system pbraries, you can create your own pbraries too, which can be stored in apppcation/pbraries folder. You can create pbraries in three ways.

    Create new pbrary

    Extend the native pbrary

    Replace the native pbrary

Create New Library

While creating new pbrary one should keep in mind, the following things −

    The name of the file must start with a capital letter e.g. Mypbrary.php

    The class name must start with a capital letter e.g. class Mypbrary

    The name of the class and name of the file must match.

Mypbrary.php

<?php if ( ! defined( BASEPATH )) exit( No direct script access allowed );
   
   class Mypbrary {
	
      pubpc function some_function() {
      }
   }
	
/* End of file Mypbrary.php */

Loading the Custom Library

The above pbrary can be loaded by simply executing the following pne in your controller.

$this->load->pbrary(‘mypbrary’);

mypbrary is the name of your pbrary and you can write it in lowercase as well as uppercase letters. Use the name of the pbrary without “.php” extension. After loading the pbrary, you can also call the function of that class as shown below.

$this->mypbrary->some_function();

Extend the Native Library

Sometimes, you may need to add your own functionapty to the pbrary provided by CodeIgniter. CodeIgniter provides facipty by which you can extend the native pbrary and add your own functions. To achieve this, you must extend the class of native pbrary class. For example if you want to extend the Email pbrary then it can be done as shown below −

Class MY_Email extends CI_Email { 
}

Here, in the above example, MY_Email class is extending the native pbrary’s email class CI_Email. This pbrary can be loaded by the standard way of loading email pbrary. Save the above code in file My_Email.php

Replace the Native Library

In some situations, you do not want to use the native pbrary the way it works and want to replace it with your own way. This can be done by replacing the native pbrary. To achieve this, you just need to give the same class name as it is named in native pbrary. For example, if you want to replace the Email class, then use the code as shown below. Save your file name with Email.php and give a class name to CI_Email.

Email.php

Class CI_Email { 
}
Advertisements