Components of MVC:
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.
Controller)
It is an intermediary between a model, a view, and any other resources necessary to process an HTTP request and generate a webpage.
Example
For example, you can use a column chart or pie chart to represent a batch of statistical data. The purpose of C is to ensure synchronization between M and V. Once M changes, V should be updated synchronously.
CI features:
Simple: CodeIgniter is authorized by the Apache/BSD-style open-source license and can be used as long as you like. Read license agreement for more information (http://codeigniter.org.cn /)
Free: CodeIgniter is truly lightweight. Our core system only needs some very small libraries, which is totally different from those that require more resources.
MVC: CodeIgniter uses the Model-View-controller (Controllers) method to better separate the presentation layer from the logic layer.
Note:
Every controller is a Class, and the function in every Class is a page. Well, this concept is very important!
Entry Method:
Entry --> Controller --> Method --> Parameter
Localhost/index. php/welcome/index
Controller:
1. What is a controller?
In short, a controller is a class file.
A user accesses a specific member method in a controller class through a URL.
And some operations are performed by the code in this method.
2. How to Create a controller
A. Create a folder \ application \ controllers
B. The class name must start with an uppercase letter.
C. inherit the core controller class CI_Controller
3. Creation Method
A. Create a member method function ()
B. The index method is accessed by default.
4. How to pass parameters to a URL
Format parameters in the Method in order after the method segment
Configure CI:
1. download the latest CI framework from the CI official website. The latest version is 2.13.
2. After decompression, there are three folders:
Configuration files used for application development, such as Model, VIew, and Control ......
System CI framework source code
User_guide User Manual
Index. php CI interface file
3. Create a folder ci in the root directory and copy application, system, and index. php to the ci folder.
4. Access: localhost/ci actual access path --> localhost/ci/index. php/welcome/index
You can use it as follows:
1. The above describes the access portal method.
Entry --> Controller --> Method --> Parameter
2. The welcome. php file in the controllers folder under application accesses the welcome_message.php file under views.
3. How is it accessed?
There is a route file routes. php In the config folder.
The path file welcome is configured.
So we can see Welcome to Codelgniter!
4. Create a business logic file in models and a View File in views
Copy codeThe Code is as follows:
/* Note that the class name (in upper case, also the file name) cannot be the same as the method name; otherwise, an error is reported. For an Index like this, there is an index method below, an error occurs */
Class Index extends CI_Controller {
Function index (){
}
}