Advantages of CodeIgniter:
- Lightweight framework
- Excellent performance
- Wide range of compatible PHP versions and configurations on standard hosts
- 0 configuration
- You do not need to use the command line
- 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=indexThe display results are as follows:
MVC Summary:
- The portal file is the only script that lets the browser request
- The controller is responsible for reconciling the model and view
- The model is only responsible for processing data
- View is only responsible for displaying data
CodeIgniter Study Notes (i)--ci Introduction and MVC design pattern