CodeIgniter Study Notes (i)--ci Introduction and MVC design pattern

Source: Internet
Author: User
Tags codeigniter

Advantages of CodeIgniter:

    1. Lightweight framework
    2. Excellent performance
    3. Wide range of compatible PHP versions and configurations on standard hosts
    4. 0 configuration
    5. You do not need to use the command line
    6. No need to stick to restrictive coding rules

CodeIgniter Latest version of: http://www.codeigniter.org.cn/

After downloading the compressed package, unzip it with the following content:

    • Application directory: A directory of programs that contains models, views, and controllers directories that implement the MVC pattern
    • System directory: CodeIgniter framework code, cannot be modified, otherwise cannot be replaced after upgrade
    • User_guide Directory: User manual, English version of
    • index.php File: Portal file
    • License.txt file: Copyright license file

Review the implementation of the MVC pattern and create a portal file index.php

<?PHPHeader("Content-type:text/html;charset=utf-8"); //Get controller name    $c=$_get[' C ']; //contains the file where the controller resides    include'./controllers/'.$c.‘ Controller.php '; //instantiating a controller    $className=$c. ' Controller '; $controller=New $className(); //Get method Name    $a=$_get[' A ']; //Calling Methods    $controller-$a();?>

Then create the data model file usermodel.php file, placed in the models directory

<?PHPclassUsermodel { Public functiongetAllUsers () {$list=Array(                    Array(' id ' =>1, ' name ' = ' Jack ', ' email ' = ' [email protected] '),Array(' id ' =>2, ' name ' = ' Mary ', ' email ' = ' [email protected] '),Array(' id ' =>3, ' name ' = ' Lili ', ' email ' = ' [email protected] '),                ); return $list; }    }?>

Then create the controller file usercontroller.php file, placed in the Controllers directory

<?PHPclassUsercontroller { Public functionindex () {//call the model method to get the data            include'./models/usermodel.php '; $model=NewUsermodel (); $list=$model-getAllUsers (); //include view file            include'./views/user/index.php '; }    }?>

Finally create the view file index.php file, placed in the views directory, here only simple display array

<! DOCTYPE html>    This is the view    of the user controller's index method <  PHP        echo "<br/>";         Var_dump ($list);    ? ></body>
Incoming controller name and method name via URL: http://localhost:8080/testCodeIgniter/mvc/index.php?c=user&a=index

The display results are as follows:

MVC Summary:

    1. The portal file is the only script that lets the browser request
    2. The controller is responsible for reconciling the model and view
    3. The model is only responsible for processing data
    4. View is only responsible for displaying data

CodeIgniter Study Notes (i)--ci Introduction and MVC design pattern

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.