Simple MVC example in getting started with the CI framework

Source: Internet
Author: User
Tags php foreach

The simplest CI model:


Note: The model needs to use the database
Configuration file in appcation/config.php
Here we need to use the database, the databases.php in the
Fill in the relevant parameters, specifically no longer repeat.


Go directly to the topic:


Mvc:

1, first talk about "M" modelthe 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 ()  {    //Connect to database    $this->load-> Database ();  }  Public function Get () {     //query database     $query = $this->db->get (' users ');     Returns the query result as an array return $query->result_array ();}  }


2, second talk about "C"with the database model and its methods, we should be extracting the data.
Controllers in CI are stored in the Application/controllers folder
Naming rules: Class name. php
such as:

Prevent illegal access if (! defined (' BasePath ')) exit (' No Direct script access allowed '); class Nb extends Ci_controller {public    fu Nction __construct ()    {parent::__construct ();                Load the data Model $this->load->model (' Nb_model ');   } Public Function Index () {        ///Data Model $data[' NB ']= $this->nb_model->get ();//Load View file $this->load-> View (' NB ', $data);}} End of File comment/* end of File nb.php *//* location:./application/controllers/nb.php */

3. Finally talk about "V"With the database model and its methods, we should be extracting the data.
Controllers in CI are stored in the Application/controllers folder
Naming rules: Class name. php (and of course not the class name, as long as the controller
Match the name of the view parameter in the
such as:




Simple MVC example in getting started with the CI 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.