我已經在另一個主題中詢問了這個主題,但是這個主題已經很冷了,而且我已經將這個主題指向了這個問題的核心。如何使用CodeIgniter將會話數據合併到函數中?
我已經在上一頁加載了會話庫,並且沒有在該頁面中工作的函數的問題。
但它是我遇到問題的下一個頁面。我收到錯誤「Unexpected T_VARIABLE」。
我讀過關於如何解決語法錯誤的主題。該主題暗示之前的行通常是問題行,通常是缺少分號或括號。
這是編碼;
public function index()
{
$this->load->model('Code_model', 'code_model');
$this->session->email //This is the problem line
$email = $this->session->email
$code = $this->input->post('code');
if ($this->code_model->find_code($email, $code))
{
$this->load->view('username');
}
else
{
$this->load->view('codeincorrect');
}
}
我已經試過把分號放在最後。並嘗試添加 - userdata('email'); 並試圖有一個單獨的功能,包含問題行與自己的括號。並嘗試刪除下面的行中的問題行&。無法找到刪除的$ email。
但沒有任何工作。
是否有人理解會話如何工作以及如何將它們集成到一個函數中?
更新
這是上一頁的控制器編碼,效果很好。
function __construct()
{
parent::__construct();
$this->load->library('session');
}
public function index()
{
$this->load->model('Email_model', 'email_model');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'required|min_length[10]|max_length[40]|valid_email|is_unique[tbl_members.email_address]', array(
'required' => 'You have not entered an %s address.', 'min_length' => 'Your %s address must be a minimum of 10 characters.',
'max_length' => 'Your %s address must be a maximum of 40 characters.', 'valid_email' => 'You must enter a valid %s address.',
'is_unique' => 'That %s address already exists in our Database.'));
if ($this->form_validation->run() == FALSE) // The email address does not exist.
{
$this->load->view('email');
}
else
{
$email = $this->input->post('email');
$random_string = chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . chr(rand(65,90));
$code = $random_string;
$this->email_model->insert_email($email, $code);
}
}
月2日更新 - 這是2個控制器編碼和2種型號
電子郵件控制器
class Email extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('session');
}
public function index()
{
$this->load->model('Email_model', 'email_model');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'required|min_length[10]|max_length[40]|valid_email|is_unique[tbl_members.email_address]', array(
'required' => 'You have not entered an %s address.', 'min_length' => 'Your %s address must be a minimum of 10 characters.',
'max_length' => 'Your %s address must be a maximum of 40 characters.', 'valid_email' => 'You must enter a valid %s address.',
'is_unique' => 'That %s address already exists in our Database.'));
if ($this->form_validation->run() == FALSE) // The email address does not exist.
{
$this->load->view('email');
}
else
{
$email = $this->input->post('email');
$random_string = chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . rand(1,9) . chr(rand(65,90)) . chr(rand(65,90));
$code = $random_string;
$this->email_model->insert_email($email, $code);
$this->load->library('email'); // Not sure if this works - testing from localhost
$this->email->from('<?php echo WEBSITE_NAME; ?>', '<?php echo WEBSITE_NAME; ?>'); // Not sure if this works - testing from localhost
$this->email->to('$email'); // Not sure if this works - testing from localhost
$this->email->subject('Code.'); // Not sure if this works - testing from localhost
$this->email->message('Select & Copy this code, then return to the website. - ','$code'); // Not sure if this works - testing from localhost
$this->email->send(); // Not sure if this works - testing from localhost
$this->load->view('code');
}
}
}
電子郵件型號
class Email_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
public function insert_email($email, $code)
{
$data = array(
'email_address' => $email,
'pass_word' => $code
);
$this->db->insert('tbl_members', $data);
return $this->db->insert_id();
}
}
代碼控制器
class Code extends CI_Controller
{
public function index()
{
$this->load->model('Code_model', 'code_model');
$this->session->email // Problem line - syntax error, unexpected '$email' (T_VARIABLE)
$email = $this->session->email
$code = $this->input->post('code');
if ($this->code_model->find_code($email, $code))
{
$this->load->view('username');
}
else
{
$this->load->view('codeincorrect');
}
}
}
代碼模型
class Code_model extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
public function find_code($code,$email)
{
$this->db->select('user_id');
$this->db->where('email_address', $email);
$this->db->where('pass_word', $code);
$code = $this->db->get('tbl_members');
if ($code->result())
{
return $this->db->delete('pass_word', $code);
}
}
}
您可以發佈您創建會話的代碼嗎 – Astound
剛剛完成。 – user225359