No1. learning points:
I. Introduction to the codeigniter framework
Ii. codeigniter framework Installation
Iii. directory structure analysis of codeigniter framework
4. How does codeigniter framework work?
5. Controller, view, model, and database operations in the codeigniter framework
6. Learning auxiliary functions, class libraries, and adapters in the codeigniter framework
7 ,......
NO2,
I. What is codeigniter?
1. codeigniter is an application framework
Codeigniter is a toolkit provided for PHP programmers who write network applications. Its goal is to achieve faster project development than writing code from scratch. For this reason, CI provides a rich set of class libraries to meet common task requirements, A simple interface and logical structure are provided to call these libraries. Codeigniter can minimize the amount of code for tasks to be completed, so that you can put more energy into project development.
2. codeigniter is free of charge.
Codeigniter is authorized by the Apache/BSD-style open-source license and can be used as long as you like.
3. codeigniter is lightweight
Our core system only requires some very small libraries, which is totally different from those that require more resources. The additional library files are loaded only when the request is made. Therefore, the core system is fast and lightweight.
4. codeigniter is fast
5. codeigniter uses the MVC model
Codeigniter uses the Model-View-controllers method to better separate the presentation layer from the logic layer. This is very useful to the template designer of the Project, which minimizes the amount of program code in the template.
6. codeigniter generates a clean URL
The URL generated by codeigniter is very clean and friendly to search engines. Unlike the standard "string query" method, codeigniter uses the segment-Based Method: example.com/news/article/121 Note: Index. the PHP file is included in the URL by default, but it can be changed. htaccess file to change this setting.
7. Powerful codeigniter Functions
Codeigniter has a full range of class libraries to complete most of the network development tasks that are commonly required, including reading databases, sending emails, confirming data, saving sessions, and performing image operations, and supports XML-RPC data transmission.
8. codeigniter is scalable
This system can be easily extended through custom class libraries and auxiliary functions, or through extension classes and system hooks.
9. codeigniter does not require a template engine
10. codeigniter has been thoroughly documented
11. codeigniter has a good user community
Note:
(1) Business process-application flowchart (how data streams run through the entire system)
(1) index. php acts as the front-end controller and initializes the basic resources required to run codeigniter. (2) The router checks the HTTP request to determine who will process the request. (3) If a cached file exists, it bypasses the normal system execution sequence and is directly sent to the browser. (4) Security ). Before the application controller is loaded, HTTP requests and data submitted by any user are filtered. (5) The Controller loads models, core libraries, auxiliary functions, and any other resources required to process specific requests. (6) The final view is rendered to the content in the Web browser. If caching is enabled, the view is first cached and can be used for future requests.
Ii. codeigniter Installation
1. Download codeigniter
Http://ellislab.com/codeigniter
Codeigniter China: http://codeigniter.org.cn/
2. Install codeigniter
There are four steps to install codeigniter: (1) decompress the installation package. (2) Upload the codeigniter folder and the files in it to your server. Usually index. php is in the root directory. (3) open application/config. php In any text editor to set the root URL of your website. If you want to use encryption or session, set your encryption key. (4) If you plan to use the database, open application/config/database. php In any text editor to set your database parameters.
3. Check whether the installation is successful.
(1) Run localhost/index. php
(2) If the operation is successful, you can see the following:
Iii. directory structure analysis in codeigniter framework
Codeinigter, a lightweight and fully functional PHP framework, allows developers to easily use the MVC structure to develop Web applications. Download a copy of codeinigter (codeigniter v 2.2.0 (Latest Version). We can see that there are five folders/files in the root directory. The user_guidefolder contains the description file, and license.txt is the license protocol and index. PHP is the main portal file, the system folder is the Framework Program directory, and the applicant folder is the project directory.
| -----System Framework Program directory | ----- core program of the core framework | ----- codeigniter. PHP guided file | ----- common. PHP loads public functions of the base class library | ----- controller. PHP base controller file: ci_controller | ----- model. PHP base model file: ci_model | ----- config. PHP configuration file: ci_config | ----- input. PHP input file: ci_input | ----- output. PHP output file: ci_output | ----- URL. php URL File: ci_url | ----- router. PHP route file: ci_router | ----- loader. PHP file loading class: ci_loader | ----- helpers auxiliary function | ----- url_helper.php URL-related auxiliary function, such: auxiliary Function for creating a URL | ----- captcha_helper.php auxiliary function for creating a graphic Verification Code | ----- libraries common class library | ----- pagination. PHP generic paging class library | ----- upload. PHP generic File Upload class library | ----- image_lib.php generic image processing class library | ----- session. PHP common session class library | ----- language Language Pack | ----- database operation-related programs | ----- db_active_rec.php quick operation file (activerecord) | ----- fonts font | ----- application project directory | ----- core program of the core project | ----- helper function of the helpers project | ----- libraries common class library | ----- language Language Pack | ----- config project-related Configuration | ----- config. configuration file related to the PHP project | ----- database. configuration file related to the PHP database | ----- autoload. PHP sets to automatically load the configuration file of the class library | ----- constants. PHP constant configuration file | ----- routes. PHP route configuration file | ----- controllers controller directory | ----- welcome. the PHP controller file inherits the ci_controller | ----- models model directory | ----- welcome_model.php model file and inherits the ci_model | ----- views directory | ----- welcome. PHP view template file. The default suffix is. PHP | ----- cache file for storing data or Templates | ----- errors error message template | ----- hooks hook, extend the system functions without modifying the system core file | ----- third_party third-party library | ----- logs log | ----- index. PHP entry file
4. How does codeigniter framework work?
1. Access Method
The access URL of codeigniter uses pathinfo, the entry file/controller/method (/parameter)
Eg: localhost/index. php/welcome/index/ID
The first section indicates calling the Controller class. The second part indicates a function or method in the call class. The third and more segments represent the parameters passed to the Controller, such as ID or other variables.
2. MVC design mode
Codeigniter is based on the Model-View-controller (MVC) design pattern. MVC is a method for separating the logic layer and presentation layer of an application. In practice, because the presentation layer is separated from the PHP script, it allows your webpage to contain only a few scripts.
- Model)Represents your data structure. Generally, your model class includes the functions of extracting, inserting, and updating your database data.
- View)Is the information displayed to the user. A view is usually a webpage, but in codeigniter, a view can also be a page segment, such as the header and end of the page. It can also be an RSS page or any other type of "page ".
- Controller)It is an intermediary between a model, a view, and any other resources necessary to process an HTTP request and generate a webpage.
Codeigniter is very loose in MVC usage, so the model is not necessary. If you do not need to use this separation method, or find that the maintenance model is much more complex than you think, you can ignore them and create your own applications and use controllers and views at least. Codeigniter can also be used together with your existing scripts, or allow you to develop the core library of this system on your own, so that you can work in the most suitable way.
3. Architecture Objectives
The goal of codeigniter is to achieve maximum execution efficiency, functionality, and flexibility in a minimal and lightweight development kit..To achieve this goal, we are committed to benchmarking, refactoring, and simplification in every step of the development process, and refuse to add anything that is not helpful for achieving the goal.
From the technical and architecture perspective, codeigniter is created according to the following objectives:
- Dynamic instantiation.In codeigniter, component import and function execution are performed only when required, rather than on a global scale. Except for the minimum core resources, it is not assumed that the system requires any resources, so the default system is very lightweight. Events triggered by HTTP requests, and the controllers and views you designed will determine when they will be referenced.
- Loose coupling.Coupling refers to the degree of correlation between components of a system. The fewer components that depend on each other, the better the reusability and flexibility of the system. Our goal is a very loosely coupled system.
- Component uniqueness.A specific component has a very small focus goal. In codeigniter, each class and its functions are highly autonomous for maximum purpose.
In short, codeigniter is a loosely coupled system that is dynamically instantiated and highly component-specific. It strives to be simple, flexible, and high-performance on a small scale.
5. Controller, view, model, and database operations in the codeigniter framework-- See user manual -- Follow-up Study
1. Controller-Controller
A controller is an intermediary between a model, a view, and any other resources necessary to process an HTTP request and generate a webpage.
A controller is a class file. Users access methods in a controller class through URLs and perform some operations by the code in this method.
Location: Project Folder \ Application \ Controllers
Note:
The class name must start with an uppercase letter and inherit from the (extends) core controller class ci_controller
The default access method is index.
After a method is disconnected, the formal parameters in the method are passed in order.
2. View-View
(1) Relationship between the Controller and the attempt
A view is a part of a webpage, such as the header, tail, and sidebar.
Controller -- call attempt: the Controller calls the relevant view based on different methods accessed by the user ($ this-> load-> View ('view filename '))
Controller-transfer data: the business data that the controller needs to present to the user to the view (data is transmitted to the view in the form of an array or object)
(2) create a view
Location: Project Folder \ Application \ views
Find the file --> create a file --> write code
Project directory \ views \ file suffix. php html code
3. Model-Model
A model is a database class. A model is designed for a table. The methods in the class are designed for specific functional requirements.
Location: Project Folder \ Application \ Models
The class name must start with an uppercase letter and inherit from the (extends) data core class ci_model. The constructor in the parent class is also overloaded.
Call the model in the Controller: $ this-> load-> model (model name );
$ This-> model name-> method name;
4. Database Operations
Note: Before operating the database, remember to modify the database. php file in config.
(1) connect to the database: $ this-> load-> database (); Note: Write it in the constructor of the model, in this way, the database is connected when the model is loaded. (2) Insert data: $ this-> database-> insert ($ t_name, $ data); $ t_name: table $ data to be operated: Data to be inserted (key name = field name, key value = field value, auto-incrementing primary key can not be written) (3) update data: $ this-> DB-> where (field name, field value); $ this-> DB-> Update (Table Name, array of modified values); (4) query data: $ this-> DB-> where (field name, field value); $ this-> DB-> select (field ); $ query = $ this-> DB-> get (Table Name); return $ query-> result (); (5) delete data: $ this-> DB-> where (field name, field value); $ this-> DB-> Delete (Table Name );
6. Learning auxiliary functions, class libraries, and adapters in the codeigniter framework-- See user manual -- Follow-up Study