Home  >  Article  >  Backend Development  >  CI (CodeIgniter) framework configuration_PHP tutorial

CI (CodeIgniter) framework configuration_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:28:39760browse

Components of MVC:

Model
represents your data structure. Typically, your model class will contain functions for retrieving, inserting, and updating data from your database.
View (View)
is the information displayed to the user. A view is usually a web page.
Controller
is an intermediary between models, views, and any other resources necessary to handle HTTP requests and generate web pages.
Example
For example, you can use a bar chart and a pie chart to represent a batch of statistical data. The purpose of C is to ensure the synchronization of M and V. Once M changes, V should be updated synchronously.

CI features:

Simple: CodeIgniter is licensed under an Apache/BSD-style open source license, you can use it as long as you want. Read the License Agreement for more information (http://codeigniter.org.cn/)
Free: CodeIgniter is truly lightweight. Our core system only requires a few very small libraries, which is completely opposite to those frameworks that require more resources
MVC: CodeIgniter uses a Model-View-Controllers approach, like this It can better separate the presentation layer and logic layer.

Special attention:

Each controller is a Class, and the function in each Class is a page. Well, this concept is very important!

Entry method:

Entrance——>Controller——>Method——>Parameter
localhost/index.php/welcome/index

Controller:

1. In the end What is a controller
In short, a controller is a class file
What the user accesses through the URL is the specific member method in a controller class
and the code in this method does the work Certain operations

2. How to create a controller
a. Create the folder applicationcontrollers
b. The class name must start with a capital letter
c. Inherit the core controller class CI_Controller

3. Creation method
a. It is to create a member method function()
b. The default access is the index method

4. How to pass URL parameters to the method
Pass the formal parameters in the method in order after the method segment

Configure CI:

1. Download the latest version of the CI framework from the CI official website. The latest version is version 2.13
2. After unzipping, there are three folders:
application Configuration files, Model, and VIew used for development , Control and other files...
system CI framework source code
user_guide User manual
index.php CI interface file
3. Create a folder ci in the root directory, and put application, system and index. Copy php to ci. You can write whatever you want in this folder
4. Then access: localhost/ci Actual access path——> localhost/ci/index.php/welcome/index

CI (CodeIgniter) framework configuration_PHP tutorial

This way you can use it. The specific instructions are as follows:

1. The entrance method it accesses is mentioned above
Entrance——>Controller——>Method——>Parameters

2. Mainly because 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 routing file routes.php under the config folder
The routing path file welcome is configured
so you can see Welcome to Codelgniter!

4. Create business logic files in models and view files in views

Copy the code The code is as follows:

/*Note that the class name (the first letter is capitalized, which is also the file name) cannot It is the same as the method name, otherwise an error will be reported. If there is an index method below an Index like this, an error will occur*/
class Index extends CI_Controller{
function index(){

}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/781409.htmlTechArticleComponents of MVC: Model (Model) represents your data structure. Typically, your model class will contain functions for retrieving, inserting, and updating data from your database. View is a display...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn