我做一些數據庫事務和設定$ new_user = TRUE這樣在模型中設置會話是不好的做法嗎?
型號代碼:
$data_insert = array
(
'username' => $username_post,
'password'=>$username_post,
);
$this->db->insert('Tenant', $data_insert);
$new_tenant_id = $this->db->insert_id();
//CREATE TABLE FOR THAT DISTRIBUTOR
$this->dbforge->add_field(
array(
'id' => array(
'type' => 'INT',
'constraint' => 10,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'site_key' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'display_name' => array(
'type' => 'VARCHAR',
'constraint' => '100',
'null' => TRUE
),
'ext' => array(
'type' => 'VARCHAR',
'constraint' => '50',
'null' => TRUE
),
'auth_user' => array(
'type' => 'VARCHAR',
'constraint' => '100',
'null' => TRUE
),
'password' => array(
'type' => 'VARCHAR',
'constraint' => '128',
'null' => TRUE,
),
'base_ini_id' => array(
'type' => 'VARCHAR',
'constraint' => '50',
'null' => TRUE
),
'md_user' => array(
'type' => 'VARCHAR',
'constraint' => '128',
'null' => TRUE
),
'uc_user' => array(
'type' => 'VARCHAR',
'constraint' => '50',
'null' => TRUE
),
'uc_password' => array(
'type' => 'VARCHAR',
'constraint' => '100',
'null' => TRUE
),
'comments' => array(
'type' => 'VARCHAR',
'constraint' => '200',
'null' => TRUE
),
'custom_ini_filename' => array(
'type' => 'VARCHAR',
'constraint' => '100',
'null' => TRUE
),
'email' => array(
'type' => 'VARCHAR',
'constraint' => '100',
'null' => TRUE
),
));
$this->dbforge->add_key('id', TRUE);
if (!$this->db->table_exists('table_name'))
{
$this->dbforge->create_table($usertable);
}
//TABLE CREATED NOW ADD SOME DATA
$insert_data = array
(
'site_key' =>$site_post,
'tenant_id'=>$new_tenant_id
);
//TENANT CREATED AND THE SITE BY HIM IS ADDED TO DATABASE
$query = $this->db->insert('MLCSites',$insert_data);
$new_user = TRUE;
現在,如果我在數據庫中的用戶,然後如果沒有$驗證設置爲TRUE我檢查$ new_user ==真,那麼我設置的loggedIn我會像這樣= TRUE:
if(!empty($validate))
{
if ($validate == TRUE)
{
// Log in user
$data = array(
'site' => $site->site_post,
'id' =>$tenant_id,
'username'=>$username_post,
'user_table'=>$usertable,
'nec_distributor'=>TRUE,
'loggedin' => TRUE,
);
$this->session->set_userdata($data);
return TRUE;
}
elseif ($new_user == TRUE)
{
// Log in user
$data = array(
'site' => $site->site_post,
'id' =>$new_tenant_id,
'username'=>$username_post,
'user_table'=>$usertable,
'nec_distributor'=>TRUE,
'loggedin' => TRUE,
);
$this->session->set_userdata($data);
return TRUE;
}
return FALSE;
}
現在在我的控制我檢查是這樣的:
$dashboard ='customer/dashboard';
$rules = $this->distributor_m->rules;
$this->form_validation->set_rules($rules);
if ($this->distributor_m->login() == TRUE)
{
var_dump($this->session->all_userdata());
$this->distributor_m->loggedin() == FALSE || redirect($dashboard);
redirect($dashboard);
}
else
{
$this->session->set_flashdata('error', 'That email/password combination does not exist');
//redirect('secure/login', 'refresh');
}
但是,當我提交用戶名和密鑰,所有數據庫事務都按照代碼成功完成。但是我的會話中沒有任何內容,如果我重新發送表單信息,那麼我會看到SESSION數據。那麼我哪裏錯了?
是否有任何與我的會話變量? – Rajan
您是否在登錄時使用ajax提交表單? –
不,我只是一個正常的提交@RajJagani – Rajan