📜  CodeIgniter-库

📅  最后修改于: 2020-10-26 05:30:29             🧑  作者: Mango


CodeIgniter框架的基本部分是其库。它提供了丰富的库集,从而间接提高了开发应用程序的速度。系统库位于系统/库中。我们需要做的就是加载我们要使用的库。可以如下所示加载库-

$this->load->library('class name');

其中,类名是我们要加载的库的名称。如果我们要加载多个库,则可以简单地将数组作为参数传递给library()函数,如下所示:

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

图书馆课程

库类位于system / libraries中。每个类都有各种功能来简化开发工作。下表显示了库类的名称及其描述。

S.N. Library Class & Description
1

Benchmarking Class

Benchmarking class is always active, enabling 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 initialized automatically.

6

Email Class

This class provides email related functionality, like send or reply to email.

7

Encryption Class

This class provides two-way data encryption functionality.

8

File Uploading Class

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

9

Form Validation Class

This class provides various functions to validate form.

10

FTP Class

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

11

Image Manipulation Class

Manipulation of image like 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 internationalization.

14

Loader Class

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

15

Migrations Class

This class provides functionalities 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 functionalities 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 like XSS Filtering, CSRF etc.

20

Session Library

This class provides functionalities to maintain session of your application.

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 functionalities to unit test your application 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.

创建库

CodeIgniter具有丰富的库集,您可以在system / libraries文件夹中找到这些库,但CodeIgniter不仅限于系统库,还可以创建自己的库,这些库可以存储在application / libraries文件夹中。您可以通过三种方式创建库。

  • 建立新图书馆
  • 扩展本机库
  • 替换本机库

建立新图书馆

在创建新库时,应牢记以下几点:

  • 文件名必须以大写字母开头,例如Mylibrary.php
  • 班级名称必须以大写字母开头,例如班级Mylibrary
  • 类名和文件名必须匹配。

Mylibrary.php

加载自定义库

只需在控制器中执行以下行即可加载上述库。

$this->load->library(‘mylibrary’);

mylibrary是您的库的名称,您可以用小写字母和大写字母书写。使用不带“ .php”扩展名的库名称。加载库后,还可以如下所示调用该类的函数。

$this->mylibrary->some_function();

扩展本机库

有时,您可能需要将自己的功能添加到CodeIgniter提供的库中。 CodeIgniter提供了便利,您可以通过它扩展本机库并添加自己的功能。为此,您必须扩展本机库类的类。例如,如果您想扩展电子邮件库,则可以如下所示进行操作-

Class MY_Email extends CI_Email { 
}

在上面的示例中,MY_Email类在这里扩展了本机库的电子邮件类CI_Email。该库可以通过加载电子邮件库的标准方法来加载。将上面的代码保存在My_Email.php文件中

替换本机库

在某些情况下,您不想以本机库的工作方式使用本机库,而是希望以自己的方式替换本机库。这可以通过替换本机库来完成。为此,您只需要提供与本机库中相同的类名即可。例如,如果要替换Email类,请使用如下所示的代码。使用Email.php保存文件名,并将类名命名为CI_Email

Email.php

Class CI_Email { 
}