Home  >  Article  >  Backend Development  >  CI framework learning essay

CI framework learning essay

WBOY
WBOYOriginal
2016-08-08 09:20:42857browse

------------------------------------------------- ----------------------------------

Codeigniter Framework

------ -------------------------------------------------- ----------------------------------

                                                                                           Weibo: weibo.com/it266

-- -------------------------------------------------- ----------------------------------

Main content

Introduction to CI

In-depth MVC design pattern

Controllers and views in CI

Super objects in CI

Database access

AR model

-------------------------------- -------------------------------------------------- ----------

What is CI?

  CodeIgniter is a lightweight but powerful PHP framework

Based on the MVC design pattern, it provides a rich set of class libraries

  Easy to learn, efficient and practical

Official website

www.codeigniter.com

Chinese Website

http://codeigniter.org.cn

Download the latest version

CodeIgniter_2.1.4.zip

(The latest version is 3.0.0 as of 2015.7.1 - author's note) What are the characteristics of

?

You want a compact framework

You need great performance

You need broad compatibility with various PHP versions and configurations on standard hosts

CI 2.1.4 requires PHP5.1.6

You want an almost exclusively A framework that requires 0 configuration

You want a framework that doesn’t require the use of any commands

You want a framework that doesn’t have to adhere to restrictive coding rules

You don’t want to be forced to learn a template language (although that’s an option Your favorite template parser)

You don’t like complexity and love simplicity

You need clear and complete documentation

Directory structure description

license.txt License agreement

user_guide User manual

syste Framework core file

application Application directory

index.php Entry file

----------------------------------------- --------------------------------------------------

MVC

1. Entry file

The only script file that the browser directly requests

2. Controller

Coordinates the model and view 3. Model

Provides data and saves data

4. View

is only responsible for displaying ... Forms ...

5. Action ACTION

is a method in the controller. The MVC

access URL in the browser uses the Pathinfo

entrance file. php/controller/action

Application directory:

controllers controllers

models models

views

The default controller is welcome

The default action is index

controller

1. No suffix required

2. The file name must be all lowercase For example user.php

3. All controllers directly or indirectly inherit from the CI_Controller class

4. In the controller, the action (method) requirements are:

public

cannot be used as _Start with

View

1. If you load the view in the controller

名 // Write the view name directly and do not write the extension. If there is a subdirectory, write the directory name

2. In the view, use the native PHP code directly

3. Recommended

& lt ;? Php foreach ($ list as $item);?>

                                                                                                                                                                                                A lot of attributes: t $ this- & gt; the instance System/Core/Loader.php

loader class provided by the load

loader class provided by:

View () loading view

VARS () allocation variable to the variable to View b database () loaded database operation objects

Model () loading model objects

helper ()

$ this-& gt; Uri

is an instance System/Core/Uri.php

Ci_uri class of CI_URI category. Method:

                                                                          using with use using                     through out through off’s off off off ‐ ‐ ‐‐‐ ‐‐ to get the parameters in the uri

​/Action/Value1/Value2

                                                               echo $this->segment(3);                                                                                                                                                                                                      . Controller/index/6

                public function index($p=0)                                         use using using using             through out through out through out ’s way out through out Through Out out through ‐ to ‐ ‐‐‐‐‐ and ​ to system/ core/input.php

Methods provided by the CI_URI class:

$this->input->post('username'); // Equivalent to $_POST['username'];

$this-> ;input->server('DOCUMENT_ROOT'); //Equivalent to $_SERVER['DOCUMENT_ROOT']; ; Use $this to access the properties in the super object

Database access

Modify the configuration file

application/config/database.php

Load the database access object into the properties of the super object $this->db

$ this->load->query($sql);//Return object

$res=$this->db->query($sql);//Return object

$res->result ();//Returns an array, the array is an object one by one

$res->result_array();//Returns a two-dimensional array, which is an associative array

$res->row()//Return The first piece of data is directly an object

The above has introduced the CI framework learning essay, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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