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中的方法
posted @ 2021-08-15 15:41  Xyang  阅读(252)  评论(0编辑  收藏  举报
hi