Let's take a simple look at the CI framework mvc. The sample code is as follows
//CI controller file home.php<?PHPdefined(' BasePath ') ORExit(' No Direct script access allowed '); To prevent the user from accessing the controller directly through the file path, it can effectively prevent the cross-site attack.classHomeextendsci_controller{//Inherit CI control class, must exist Public function__construct () {Parent::__construct (); $this->load->model (' Home_model '); Load Model class} Public functionindex () {Echo' Home Page '; $this->load->view (' Home/index '); Render the Index view page under Home, view can be lowercase}
// CI model class file hone_model.php<? PHP class extends Ci_model { function __construct () { parent::__construct (); $this->load->database (); Load Database }}
Page effects
To solve the problems encountered:
1, an error occurred while accessing CI in Linux deployment Unable to locate the model when you had Specified:*_model
Workaround: The above problem is not found in the specified model class, the main reason is because the window environment code is not case-sensitive, so the default model class file name I lowercase, but the file class name must be uppercase, when we loaded the project into the Linux environment, The Linux environment is case-sensitive, so the class file could not be found, the problem occurs, we want to modify the model class filename and the controller's load name is consistent, either all lowercase or the first letter uppercase, the remaining letters are all lowercase. The class name in the model class is guaranteed to be capitalized, with the remaining lowercase formatting.
For example, the above example guarantees the $this->load->model (' Home_model '); Both the load name and the model class file name are consistent Home_model.
2, Error message:undefined Property:home:: $load
Workaround: This problem occurs because the controller file name (class name) We define uses the keyword in CI to cause naming conflicts, there are two workarounds, the first to modify the controller file name and class name (this method is relatively troublesome, we recommend the second method), the second one in the controller type to add a constructor, The wording is as follows
Public function __construct () { parent::__construct (); }
Simple use of the PHP CI Framework (ii)