CI Framework Learning Essays

Source: Internet
Author: User
Tags access properties php foreach php framework codeigniter
---------------------------------------------------------------------------------------

CodeIgniter Frame

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

Lecturer: Shi Yiliang

Weibo: weibo.com/it266

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

Main content

About CI

In-depth MVC design Patterns

controllers and views in CI

The Super object in CI

Database access

AR model

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

What is CI?

CodeIgniter is a lightweight but powerful PHP framework

Provides a rich set of class libraries based on the MVC design pattern

Easy to learn, efficient and practical

Official website

Www.codeigniter.com

Chinese website

http://codeigniter.org.cn

Download current Latest Version

Codeigniter_2.1.4.zip

(As of 2015.7.1, the latest version of the 3.0.0--author note)

What are the characteristics?

You want a small frame.

You need great performance.

You need to be broadly compatible with various PHP versions and configurations on the standard host

CI 2.1.4 Need PHP5.1.6

You want a framework that is almost only 0 configured

You want a framework that doesn't need to use any of the command characters

You want a framework that doesn't need to stick to restrictive coding rules.

You don't want to be forced to learn a template language (although you can choose the template parser you like)

You don't like complexity, love simple.

You need clear, complete documentation

Directory Structure Description

License.txt License Agreement

User_guide User Manual

Syste Framework Core File

Application application Directory

index.php Portal File

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

Mvc

1. Entry file

The only script file that allows the browser to request directly

2. Controller

Reconcile Models and views

3. Model

Provide data, save data

4. View

Only the display is responsible

Form ...

5. Actions action

is a method in the controller that is used by the browser to request

MVC in CI

The access URL is using the PathInfo

Entry file. php/Controller/action

In the application directory:

Controllers Controller

Models model

Views View

The default controller is welcome

The default action is index

Controller

1. No suffix required

2. File name all lowercase such as user.php

3. All controllers, directly or indirectly, inherit from the Ci_controller class

4. In the controller, the action (method) requires:

Public

Cannot start with _

View

1. In the controller if the view is loaded

Write the view name directly, do not write the extension, if there is a subdirectory, write the directory name

2. View, directly using native PHP code

3. Recommended Use

Super Object

The current Controller object

Provides a number of properties:

$this->load

instance of the loader class system/core/loader.php

The method provided by the loader class:

View () Load views

VARs () assigning variables to views

Database () to mount databases operation objects

Model () To load models object

Helper ()

$this->uri

is an instance of the Ci_uri class system/core/uri.php

Methods provided by the Ci_uri class:

Segment () to get the parameters in the URI

Traditional: Entry file. php/controller/action/parameter 1/value 1/parameter 2/value 2

Entry file. php/controller/action/value 1/value 2

Echo $this->segment (3);//value 1

Echo $this->segment (4);//value 2

index.php/Controller/INDEX/6

Public Function Index ($p =0) {echo $p;//Output 6

}

$this->input

Input class

is an instance of the Ci_uri class 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 ');

$this->input->server (' remote_addr ');

In the view, use $this directly to access properties in the Super object

Database access

Modifying a configuration file

application/config/database.php

Mount 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 that is an object of one in the array

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

$res->row ()//returns the first data, directly an object

The above describes the CI framework learning essays, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.