我的模型中有一個函數檢查登錄表單中給出的憑證。它選擇email
,senha
和tipo_pessoa
。以下是功能:使用CodeIgniter中的查詢結果設置會話值3
public function find_credentials()
{
$this->db
->select('email, senha, tipo_pessoa')
->from($this->table)
->where('email', $this->input->post('email'))
->where('senha', md5($this->input->post('password')));
$query = $this->db->get();
if ($query->num_rows() == 1) {
return true;
}
return false;
}
無論前一個函數的結果如何,位於我的控制器中的下一個函數都會執行。它決定根據返回的結果做什麼:
public function validate_credentials()
{
if ($this->Usuarios_fisica_model->find_credentials()) {
$data = array();
$data['email'] = $this->input->post('email');
$this->session->set_userdata($data);
$this->session->set_flashdata('message', 'Bem-vindo!');
redirect('/', 'refresh');
} else {
$this->session->set_flashdata('message', 'Desculpe, credenciais inválidas');
redirect('/');
}
}
我需要存儲tipo_pessoa
在會話來確定哪些頁面的用戶應該被重定向到。對於兩種不同類型的用戶,我有兩個不同的表格,每種都有自己的頁面。
編輯*
建議的解決方案之後,我加入到我的頭文件,下面的代碼來呼應tipo_pessoa
:
<div class="menu_login">
<?php if ($this->session->userdata('email')) { ?>
<span><?php echo $this->session->userdata('email'); ?></span>
<span><?php echo $this->session->userdata('tipo_pessoa'); ?></span>
<a href="<?php echo base_url('usuario/painel'); ?>" class="bt_entre">Ir ao Painel</a>
<a href="<?php echo base_url('usuario/sair') ?>" class="bt_cadastre">Sair</a>
<?php } else { ?>
<span>Minha Conta</span>
<a href="#" id="bt_entrar" class="bt_entre">Entre</a>
<a href="<?php echo base_url('cadastro') ?>" class="bt_cadastre">Cadastre-se</a>
<?php } ?>
</div>
'tipo_pessoa'是什麼類型的數據?詮釋?串? – DFriend
在你的代碼中是'$ this-> session-> set_userdata('tipo_pessoa',$ tipo_pessoa);'? – Kisaragi
@Kisaragi我的確如你所回答的那樣。 – mfgabriel92