2017-05-30 5 views
0

私はこのトピックを別のトピックで尋ねましたが、そのトピックは寒くなりました。私はこのトピックを問題の中核に向けました。CodeIgniterを使用してセッションデータを関数にマージするには?

セッションライブラリを前のページにロードしましたが、そのページで機能している関数に問題はありません。

しかし、私は問題が発生している次のページです。エラー "予期しない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')を追加しようとしました。 そして、それ自身の括弧で問題の行を含む別の関数を持つことを試みました。問題の行を削除しようとしました&以下の行。削除された$電子メールが見つからない場合。

しかし、何も動作しません。

セッションの仕組みや機能の理解方法を理解している人はいますか?

更新

これは正常に機能する前のページのコントローラコーディングです。

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つのモデルである

メールコントローラ

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); 
} 
} 
} 
+0

あなたはセッションを作成したコードを投稿することができます – Astound

+0

ちょうどそれを行いました。 – user225359

答えて

0

セッションライブラリがロードされていることを確認します。あなたは言って手動でこれを行うことができます。

$this->load->library('session');

しかし、あなたは、それはすべての回でロードしたい場合は、あなたのautoload.phpファイルに移動し、必ずセッションを作るautoload['libraries']エリアに追加されます。

+0

最近の編集をご覧ください。 – user225359

0

コードはバグのようです。以下を確認してください。 PHP文で

  1. はセミコロン(;
  2. $this->session->emailによって終了される:セッション配列からemail要素の値を返し、それがコード$email = $this->session->emailのように次のラインのように、割り当てられるべきです。
  3. emailは運のベストprint_r($this->session->all_userdata());

セッションで設定されているかどうかをチェック!

+0

私はあなたの批評を完全に理解していません。私が最後にセミコロン(;)を置くと、私はまだエラーが発生します。 print_r($ this-> session-> all_userdata())を挿入しました。問題の行の後にコードのバランスをコメントアウトしたが、このエラーが発生する - 構文エラー。予期しない 'print_r'(T_STRING) - コードを書き直して答えることができますか? – user225359

+0

完全なコントローラとモデルコードをここに入れてください。実際のバグを見つけるのに役立ちます。 –

+0

よろしくお願いします。私はちょうどそのコードを挿入しました。 – user225359

関連する問題