Simple use of the PHP CI Framework (ii)

Source: Internet
Author: User

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)

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.