<?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打交道:
复制代码 代码如下: