Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26188145
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类:

2009-08-17 00:34:24

1.你可以写一个模型类,里面包含插入、更新、删除Blog数据的方法(模型的作用!)
2.

模型可以在 中被引用。 就像这样:

$this->load->model('Model_name');

(控制器中引入模型进来!)
$this->load->model('Model_name'); 加载

$this->Model_name->function();    调用里面方法

class Blog_controller extends Controller {

    function blog()
    {
        $this->load->model('Blog');

        $data['query'] = $this->Blog->get_last_ten_entries();

        $this->load->view('blog', $data);
    }
}


自动载入模型

如果您需要一个在整个项目中都起作用的特定模型,您可以让 CodeIgniter 在初始化时自动装载它。实现的方法是打开 application/config/autoload.php 文件,然后在自动装载数组中添加上这个模型。




阅读(1021) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~