最简单的CI模型:

注意:模型须要用到数据库
配置文件在appcation/config.php
这里我们要用到数据库,须要将databases.php中的
相关參数填写一下,详细不再赘述。

直接进入主题:

MVC:

1、首先谈“M” 模型

CI中的模型存放在application/models目录里
命名规则是:类名_model.php
文件里仅仅包括一个类:

如:

class Nb_model extends CI_Model {

  public function __construct()
{
//连接数据库
$this->load->database();
} public function get(){
//查询数据库
$query=$this->db->get('users');
//以数组形式返回查询结果
return $query->result_array();
}
}

2、其次谈“C”

有了数据库模型及其方法。那么我们就该提取数据了
CI中的控制器存放在application/controllers目录中
命名规则:类名.php
如:

//防止非法訪问
if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Nb extends CI_Controller { public function __construct()
{
parent::__construct();
//载入数据模型
$this->load->model('nb_model'); } public function index()
{
//依据数据模型获取数据
$data['nb']=$this->nb_model->get();
//载入视图文件
$this->load->view('nb',$data);
}
}
//文件末尾凝视
/* End of file nb.php */
/* Location: ./application/controllers/nb.php */

3、最后谈“V”

有了数据库模型及其方法。那么我们就该提取数据了
CI中的控制器存放在application/controllers目录中
命名规则:类名.php(当然也能够不是类名。仅仅要是跟控制器
          中的view传參的名字一致就可以)
如:

<html>
<head>
<title>CI heiilo world</title>
</head>
<body>
<!--循环输出数据-->
<?php foreach($nb as $v):?>
<h1><?=$v['email']?></h1>
<? php endforeach?>
</body>
</html>

最新文章

  1. javascript中的事件冒泡和事件捕获
  2. 配置java环境 ,安装Android Studio...(ps:用eclipse也不错,但as是趋势 自己凭爱好选择)
  3. 关于 Google Chrome 中的全屏模式和 APP 模式
  4. 编写更好的CSS
  5. POJ 2524 (简单并查集) Ubiquitous Religions
  6. 使用在storyBoard之外的xib创建对象
  7. 基本STRUTS标签-学习笔记-Logic标签
  8. Soap UI 数据库脚本(转)
  9. OpenJudge/Poj 1657 Distance on Chessboard
  10. View not attached to window manager crash 的解决办法
  11. CodeForces 669D Little Artem and Dance
  12. Undefined symbols for architecture armv7错误解决方法
  13. ASP.NET Core的身份认证框架IdentityServer4(9)-使用OpenID Connect添加用户认证
  14. bcache的使用
  15. Redis纠错
  16. linux命令:查看系统版本
  17. CF1000G
  18. JavaScript HTML DOM 元素操作(节点)
  19. poj1062昂贵的聘礼(枚举+最短路)
  20. Python网络爬虫笔记(四):使用selenium获取动态加载的内容

热门文章

  1. 八皇后II
  2. 深入理解ajax系列第九篇
  3. Qt中使用Json
  4. github下载项目
  5. HDU 4641 K-string 后缀自动机 并查集
  6. 【BZOJ】4318: OSU!【期望DP】
  7. Shell 学习笔记之函数
  8. javascript中的lambda表达式
  9. LogStash日志分析系统
  10. HOWTO: Get the command line of a process(转)