Simple MVC example in getting started with 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, we need to databases.php in the
To fill in the relevant parameters, detailed no longer repeat.




Go directly to the topic:


Mvc:

1, first talk about "M" modelthe model in CI is stored in the Application/models directory.
The naming rule is: Class name _model.php
The file contains only a single 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"the database model and its methods are available. Then we should be extracting the data.
Controllers in CI are stored in the Application/controllers directory
Naming rules: Class name. php
such as:

Prevent illegal access to the IF (! defined (' BasePath ')) exit (' No direct script '); class Nb extends Ci_controller {public    fu Nction __construct ()    {parent::__construct ();                Load 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);}} File End Gaze/* End of File nb.php *//* location:./application/controllers/nb.php */

3. Finally talk about "V"the database model and its methods are available. Then we should be extracting the data.
Controllers in CI are stored in the Application/controllers directory
Naming rules: Class name. PHP (and certainly not the class name.) Just with the controller.
? ? ? ? ? The name of the view will be the same.
such as:

PHP endforeach?> </body>




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