[請益] MVC model超新手問題-use CI
初嘗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
{
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==
-
非常感謝您閱讀完畢!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.118.232.236
→
06/07 23:02, , 1F
06/07 23:02, 1F
→
06/07 23:03, , 2F
06/07 23:03, 2F
→
06/07 23:15, , 3F
06/07 23:15, 3F
→
06/07 23:19, , 4F
06/07 23:19, 4F
→
06/07 23:20, , 5F
06/07 23:20, 5F
→
06/07 23:23, , 6F
06/07 23:23, 6F
→
06/08 01:20, , 7F
06/08 01:20, 7F
→
06/08 01:28, , 8F
06/08 01:28, 8F
→
06/08 02:03, , 9F
06/08 02:03, 9F
→
06/08 20:36, , 10F
06/08 20:36, 10F
→
06/08 20:36, , 11F
06/08 20:36, 11F
→
06/08 20:37, , 12F
06/08 20:37, 12F
→
06/08 21:46, , 13F
06/08 21:46, 13F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章
4
20
6
17