如何让CI框架支持service层(2)


<?php
class User extends CI_Controller
{
    public function __construct()
    {
  
        parent::__construct();
        $this->load->service('user_service');
    }
    public function login()
    {
        $name = 'phpddt.com';
        $psw = 'password';
        print_r($this->user_service->login($name, $psw));
    }
}

service中调用model :

复制代码 代码如下:


<?php
class User_service extends MY_Service
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('user_model');
    }
    public function login($name, $password)
    {
        $user = $this->user_model->get_user_by_where($name, $password);
        //.....
        //.....
        //.....
        return $user;
    }
}

model中你只跟db打交道:

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/b6c23a80b51f0ee93b1d6c2fa66df679.html