ci-Model使用方法

1.News.php中News类继承ci_model

class News extends CI_Model{
public function getAll()
    {
        $this->load->database();//加载数据库
        $res=$this->db->query('select * from news');//执行查询语句
        var_dump($res->result());
    }
}
2.Controller中加载model
  $this->load->model('News');或者可以写成  $this->load->model('News','news');
  $this->News->getAll();执行model中的方法
原文地址:https://www.cnblogs.com/xyangs/p/15143583.html