Introduction to CI framework MVC simple Example _php instance

Source: Internet
Author: User
Tags php foreach codeigniter zend framework

The example in this article describes the MVC simple example of getting started with the CI framework. Share to everyone for your reference, specific as follows:

The simplest CI model:

Note: The model needs to use a database

Configuration file in appcation/config.php

Here we want to use the database, need to databases.php in the relevant parameters to fill out, specifically no longer repeat.

Directly into the subject:

Mvc:

1, first talk about "M" model

The model in CI is stored in the Application/models folder.

The naming rule is: Class name _model.php

The file contains only one class:

Such as:

Class Nb_model extends Ci_model {public
 function __construct ()
 {
  //Connection database
  $this->load-> Database ();
 }
 Public function Get () {
   //query database
   $query = $this->db->get (' users ');
   Returns the result of the query as an array return
   $query->result_array ();
 }


2, the second talk about "C"

With the database model and its methods, we should extract the data.

The controllers in CI are stored in the Application/controllers folder

Naming rules: Class name. php

Such as:

Prevents illegal access to
if (! defined (' BasePath ')) exit (' No Direct script access allowed ');
Class Nb extends Ci_controller {public
  function __construct ()
  {
    parent::__construct ();
        Load data Model
    $this->load->model (' Nb_model ');
  }
  The Public Function index ()
  {
    //obtains data based on the data model
    $data [' nb ']= $this->nb_model->get ();
    Load view file
    $this->load->view (' NB ', $data);
  }
Note/* End of File
nb.php
/* Location:./application/controllers/nb.php/*

3, the last talk about "V"

With the database model and its methods, we should extract the data.

The controllers in CI are stored in the Application/controllers folder

Naming rules: Class name. php (or, of course, not a class name, as long as it is consistent with the name of the View argument in the controller)

Such as:

 
 

More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on CodeIgniter framework.

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.