|
本帖最后由 hareino08 于 2013-6-7 23:24 编辑
自己打錯 已經解決 謝謝大家!!
初尝CI 初用MVC架构@@
请大家多指教,并见谅我的白痴问题=口=
我有一个controller 在construct时
load 一个叫做(access) 的model 进来
里面写的是一些当前使用者权限处理之类的函数
==Model: access.php==
function islogin()
{
$this->load->library('session');
return ($this->session->userdata('is_login')==TRUE) ? (TRUE)
: (FALSE);
}
function noaccess()
{
if($this->islogin()==FALSE)
{
die("Access Denied");
}
}
==
AND 这个controller我是要用来做系统登入
所以後面有 个函数来做 帐号密码判断
==
$this->load->model("administrator/user");
$get_uid = $this->user->user_check($_POST['username'],$_POST['password']);
==
=Model: user.php==
function user_check($username,$password)
{
$query = $this->db->query("select uid from _user where
_username='$username' && _password='".md5($password)."'");
$row = $query->row();
return (isset($row->uid)) ? ($row->uid) : (FALSE);
}
==
就变成总共载入了两个model到一个controller里
但是这样第2个载入进来的会出错T_T
询问了前辈,他说只能载入一个?
但这样要怎麽做呢? 移到libary里用libary方式载入?
还是说...我的MVC架构根本有问题QQ
恳请各位大师指教!!
--
伤眼时间开始~
附上完整档案内容:
--
==Controller: process.php==
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Process extends CI_Controller
{
private $is_login;
function __construct()
{
parent::__construct();
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
$this->load->library('session');
$this->load->model("administrator/access");
$this->islogin = $this->access->islogin();
}
function index()
{
}
function login()
{
$echo_data = array();
if($this->islogin)
{
$echo_data["status"] = 0;
}
else
{
if($_POST['safecode']==""||$_POST['username']==""||$_POST['password']=="")
{
$echo_data['status'] = 1;
}
else
{
if($_POST['safecode']==$this->session->userdata('safecode'))
{
$this->load->model("administrator/user");
$get_uid =
$this->user->user_check($_POST['username'],$_POST['password']);
if($get_uid==FALSE)
{
$echo_data['status'] = 3;
}
else
{
$echo_data['db'] = $get_uid;
$this->session->set_userdata(array("is_login"=>TRUE,"uid"=>$get_uid,"username"=>$_POST['username']));
$echo_data['status'] = 4;
}
}
else
{
$echo_data['status'] = 2;
}
}
}
$this->session->unset_userdata('safecode');
echo json_encode($echo_data);
}
function logout()
{
$this->access->noaccess();
$this->session->sess_destroy();
}
}
?>
==END==
==Model: access.php==
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Access extends CI_Controller <= X
CI_Model
{
function islogin()
{
$this->load->library('session');
return ($this->session->userdata('is_login')==TRUE) ? (TRUE)
: (FALSE);
}
function noaccess()
{
if($this->islogin()==FALSE)
{
die("Access Denied");
}
}
}
?>
==END==
==Model: user.php==
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
function user_check($username,$password)
{
$query = $this->db->query("select uid from _user where
_username='$username' && _password='".md5($password)."'");
$row = $query->row();
return (isset($row->uid)) ? ($row->uid) : (FALSE);
}
}
?>
==END==
-
非常感谢您阅读完毕!!
|
|