什么是CodeIgniter,它如何工作?

()

什么是CodeIgniter? (What is CodeIgniter?)

CodeIgniter is a free, open-source, easy-to-use, object-oriented PHP web application framework, providing a ready-to-use library to use with your own PHP applications. For example, there is a Database API to make it easier and more convenient to execute SQL queries, such as SELECT, UPDATE, DELETE, INSERT, etc., without having to create a lot of repetitive code yourself. This is how an application framework is useful in application development.

CodeIgniter是一个免费的,开源的,易于使用的,面向对象PHP Web应用程序框架,提供了可与您自己PHP应用程序一起使用的现成库。 例如,有一个数据库API使执行SQL查询(例如SELECT,UPDATE,DELETE,INSERT等)更加容易和方便,而无需自己创建大量重复代码。 这就是应用程序框架在应用程序开发中的有用方式。

CodeIgniter是面向对象的 (CodeIgniter is object-oriented)

Using CodeIgniter requiring knowledge of using the object-oriented programming technique in order to be able to use CodeIgniter effectively, and to understand what happens when you are using certain features in CodeIgniter.

使用CodeIgniter需要具备使用面向对象编程技术的知识,以便能够有效地使用CodeIgniter,并了解在CodeIgniter中使用某些功能时会发生什么。

但是,什么是面向对象的编程? (But, what is object-oriented programming?)

It’s quite difficult to explain object-oriented programming because from a conceptual point of view, it is difficult to understand. However, the main purpose of object-oriented programming is to make application development easier, especially as applications become bigger, with large structures. Object-oriented programming allows application code and logic to be easier to understand, structured and coherently in place, making it easier to develop and extend your application’s features and functionality. With procedural programming (which is merely standard code executed line-by-line with the use of functions as a container for code that help prevent repetitiveness and “reinventing the wheel”), applications can become a mess if they aren’t developed in a way where everything is well laid out, coherent and structured, and can be more difficult to extend and add new features and functionality to your applications later on. With object-oriented programming, in a way, you are forced to be coherent and have your code structured correctly.

解释面向对象的编程非常困难,因为从概念上讲,这很难理解。 但是,面向对象编程的主要目的是使应用程序开发更容易,尤其是当应用程序变得更大且结构较大时。 面向对象的编程使应用程序代码和逻辑更易于理解,结构化和连贯一致,从而使开发和扩展应用程序的功能更加容易。 使用过程性编程(这只是逐行执行的标准代码,并使用函数作为代码容器来帮助防止重复和“重新发明轮子”),如果应用程序不是在一个程序库中开发的,它们可能会变得一团糟。这样一来,所有内容都可以很好地布局,连贯和结构化,并且在以后扩展和向应用程序添加新特性和功能时可能会更加困难。 在某种程度上,通过面向对象的编程,您必须保持一致,并使代码的结构正确。

类和方法 (Classes and Methods)

What are classes and methods? These are the first concepts you’ll be introduced to if you are learning object-oriented programming from most books or online resources. Say you’re creating a framework. You’ll have different classes for different parts of your framework. One being a “Database Class”, one being an “E-mail Class”, and so forth. Of course, in this case, the Database Class is like the CodeIgniter Database Class, providing a set of ready-made methods for you to use so you don’t have to create them yourself in order to execute certain application logic, such as inserting, updating and removing database records quickly, without having to “reinvent the wheel”.

什么是类和方法? 如果要从大多数书籍或在线资源中学习面向对象的编程,那么将是第一个引入这些概念。 假设您正在创建一个框架。 您将为框架的不同部分使用不同的 。 一个是“数据库类”,一个是“电子邮件类”,依此类推。 当然,在这种情况下,数据库类类似于CodeIgniter数据库类,它提供了一组现成的方法供您使用,因此您不必自己创建它们即可执行某些应用程序逻辑,例如插入,快速更新和删除数据库记录,而无需“重新发明轮子”。

The methods are what contain the application logic, and the class merely holds many related methods together. And this is exactly how your applications would work with the use of the object-oriented programming techniques.

这些方法包含应用程序逻辑,而该类仅将许多相关方法结合在一起。 这正是您的应用程序将使用面向对象编程技术的方式。

CodeIgniter如何工作? (How does CodeIgniter work?)

CodeIgniter has a very extensive user guide, which is much better than documentation on some other frameworks, such as CakePHP (which is another PHP framework).

CodeIgniter 有一个非常详尽的用户指南 ,比其他一些框架(例如CakePHP,这是另一个PHP框架 )上的文档要好得多。

CodeIgniter has classes and helpers.

CodeIgniter有助手

班级 (Classes)

Classes contain a collection of methods and properties (properties are essentially variables in an object-oriented context).

类包含方法和属性的集合(属性在面向对象的上下文中本质上是变量)。

For example, here is an example using the Database library within CodeIgniter:

例如,下面是在CodeIgniter中使用数据库库的示例:

$this->db->get(‘users’,$data);

$ this-> db-> get('users',$ data);

In any application you make using CodeIgniter, your own classes inherit (or extends) the CodeIgniter class, and so this is why the $this variable is used, which refers to the current class/object. So to call another method within your class, you would use $this->method_name().

在使用CodeIgniter创建的任何应用程序中,您自己的类都继承(或扩展了 )CodeIgniter类,因此这就是使用$ this变量的原因, 变量引用当前的类/对象。 因此,要在您的类中调用另一个方法,可以使用$ this-> method_name()。

帮手 (Helpers)

Helpers contain ordinary PHP functions. Such as the Form Helper.

助手包含普通PHP函数。 如Form Helper

CodeIgniter的其他有趣功能 (Other interesting features of CodeIgniter)

While this is by no means unique to CodeIgniter, and other web application frameworks use this approach to application development, CodeIgniter primarily uses the Model, View, Controller (MVC) approach to application design and development. It essentially separates application logic from the application design/view. The application logic is the Controller, whereas the application design/view is the View. The Model is for database interactions. There are more complex scenarios where the MVC approach is used, but for basic to intermediate CodeIgniter applications, the Model would contain database interactivity logic of sorts.

尽管这并不是CodeIgniter独有的,其他Web应用程序框架也使用这种方法进行应用程序开发,但是CodeIgniter主要使用模型,视图,控制器 (MVC)方法进行应用程序设计和开发。 它从本质上将应用程序逻辑与应用程序设计/视图分开。 应用程序逻辑是Controller,而应用程序设计/视图是View 。 该模型用于数据库交互。 在更复杂的场景中使用MVC方法,但是对于基本到中间的CodeIgniter应用程序, 模型将包含各种数据库交互逻辑。

活动记录 (Active Record)

When you saw an example of using the Database Class above, that code is actually part of the Active Record Class that is part of the Database library.

当您在上面看到使用数据库类的示例时,该代码实际上是数据库数据库中活动记录类的一部分。

Active Record is where your work can be shortened by providing an easy and convenient way to execute certain SQL queries without having to write out the entire SQL query yourself. Active Record essentially allows information to be updated, retrieved, added and removed conveniently.

通过Active Record,您可以提供一种简便的方法来执行某些SQL查询,而不必自己写下整个SQL查询,从而可以缩短您的工作。 Active Record本质上允许方便地更新,检索,添加和删除信息。

有关CodeIgniter的更多信息 (More information on CodeIgniter)

The CodeIgniter framework works on all of our shared and reseller servers, and can be installed on pretty much any server with PHP installed. As of writing, CodeIgniter requires PHP version 5.1.6 or higher and obviously a database will be required for any database-driven PHP application (as of writing, MySQL 4.1 or higher). CodeIgniter also supports PostgreSQL, Oracle, SQLite and ODBC. For up to date server requirements, see the CodeIgniter user guide.

CodeIgniter框架可在我们所有共享和转售服务器上使用,并且几乎可以安装在任何装有PHP的服务器上。 在撰写本文时,CodeIgniter需要PHP 5.1.6或更高版本,并且显然任何数据库驱动PHP应用程序都将需要数据库(在撰写本文时,MySQL 4.1或更高版本)。 CodeIgniter还支持PostgreSQL,Oracle,SQLite和ODBC。 有关服务器的最新要求, 请参见CodeIgniter用户指南

访问CodeIgniter网站 (Visit the CodeIgniter website)

翻译自: https://www.eukhost.com/blog/webhosting/what-is-codeigniter-and-how-does-it-work/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值