ライブラリをロードすると、codeigniter がセッションを設定することを理解しています。でも、自分なりのルールを作りたい。ユーザーデータを追加し、ページの読み込みごとに存在するかどうかを確認することで、それができると思いました。しかし、それは機能していません...
これが私のウェルカムコントローラーです...
class Welcome extends CI_Controller
{
function __construct()
{
parent::__construct();
//$this->output->enable_profiler(TRUE);
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library('session');
$this->load->helper('url');
}
function index($cliqid='', $cliq=false)
{
$default_cliq = 5; //this equals whatever the user sets
$this->page_m->load_session($default_cliq); //check to see if session is new; if so, perform list of actions
//$this->session->sess_destroy();
print_r($this->session->all_userdata());
}
}
これは、訪問者がページに滞在している間、いくつかのセッション変数を適用するロード セッション メソッドで構成される page_m を指しています。
以下に簡単な抜粋を示します。
class Page_m extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->model('cliq_info_m');
}
function load_session($default_cliq)
{
//check if session is new
if ($this->session->userdata('exists') == true) {
//the list of things to do
$this->record_session(); //check if ip exists in DB, if not, record
$this->cliq_info_m->change_active($default_cliq);
//make session old
$data['exissts'] = true;
$this->session->set_userdata($data);
} else {
return false;
}
}
何が起こるか...「exists」変数に関係なく、毎回これを実行します。
理由を知っている人はいますか?そして可能な解決策は?