私のCodeIgniterコントローラが2回呼び出されている問題があります。それはuri(/ newsletter/confirm/a1938cas893vf9384f0384f0943)のパラメータを使用しているときにのみ発生するようです。関数からパラメータを削除すると、コントローラは一度だけロードされます。私はまた、URLのパラメータで、ページをリフレッシュすると、一度だけロードされることに気付きました。したがって、新しいページが呼び出されたときにのみ2回ロードされているようです。CodeIgniterコントローラURLでパラメータを使用するときに2回ロードする
たとえば、初めて/ newsletter/confirm/a123にナビゲートすると、初めて2回読み込まれます。しかし、あなたがリフレッシュするなら/ newsletter/confirm/a123それは一度だけロードされます。私はそれを引き起こすビューで問題を排除するために私の見解に対するコメントを終えました。
これはキャッシュの問題、または.htaccessファイル内の何かのように聞こえますか?ご意見ありがとうございます。
関連コントローラ:
<?php
error_reporting(-1);
ini_set('display_errors',1);
class Test extends CI_Controller {
function __construct() {
parent::__construct();
log_message('debug', 'MyController initialised');
}
function confirm($code)
{
$this->load->helper(array('form'));
//$code = "6e930fe882c3b15712158812769dbcb636f96b8c";
$result = $this->db->get_where('newsletter_members', array('nm_confirmation_code' => $code, 'nm_subscribed' => 0));
if ($result->num_rows == 0)
{
$newsletter_message['newsletter_message'] = "Confirmation code is invalid or has already been confirmed.";
//$this->load->view('index_test', $newsletter_message);
} else {
$newsletter_message['newsletter_message'] = "Thank you for confirming your intent to subscribe to our newsletter!";
$data = array(
'nm_subscribed' => 1,
);
$this->db->where('nm_confirmation_code', $code);
$this->db->update('newsletter_members', $data);
//$this->load->view('index_test', $newsletter_message);
}
}
}
?>
.htaccessファイル:
RewriteEngine On
RewriteCond $1 !^([^\..]+\.php|robot\.txt|public|images|css|js|paul|event_docs|blog|citeforme|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
# BEGIN WordPress
#<IfModule mod_rewrite.c>
#RewriteEngine On
#RewriteBase/
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [L]
#</IfModule>
#RewriteEngine Off
# END WordPress
は、ここではすべてが二回再ロードされて見ることができ、同様にログファイルが見えるものです:
DEBUG - 2011-09-16 09:59:34 --> Config Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Hooks Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Utf8 Class Initialized
DEBUG - 2011-09-16 09:59:34 --> UTF-8 Support Enabled
DEBUG - 2011-09-16 09:59:34 --> URI Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Router Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Output Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Input Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Global POST and COOKIE data sanitized
DEBUG - 2011-09-16 09:59:34 --> Language Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Loader Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Database Driver Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Controller Class Initialized
DEBUG - 2011-09-16 09:59:34 --> MyController initialised
DEBUG - 2011-09-16 09:59:34 --> Helper loaded: form_helper
DEBUG - 2011-09-16 09:59:34 --> Final output sent to browser
DEBUG - 2011-09-16 09:59:34 --> Total execution time: 0.0223
DEBUG - 2011-09-16 09:59:34 --> Config Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Hooks Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Utf8 Class Initialized
DEBUG - 2011-09-16 09:59:34 --> UTF-8 Support Enabled
DEBUG - 2011-09-16 09:59:34 --> URI Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Router Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Output Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Input Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Global POST and COOKIE data sanitized
DEBUG - 2011-09-16 09:59:34 --> Language Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Loader Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Database Driver Class Initialized
DEBUG - 2011-09-16 09:59:34 --> Controller Class Initialized
DEBUG - 2011-09-16 09:59:34 --> MyController initialised
DEBUG - 2011-09-16 09:59:34 --> Helper loaded: form_helper
DEBUG - 2011-09-16 09:59:34 --> Final output sent to browser
DEBUG - 2011-09-16 09:59:34 --> Total execution time: 0.0213
メッセージをどこかに記録します。コントローラの親クラスは__construct関数で同じことを行います。したがって、エラーログに「My controller initialised」という2つのエラーメッセージが表示され、「Controller Class Initialized」という2つのエラーメッセージが表示されます。 –
はい、Calleですが、それらは2回読み込まれるだけではなく、すべてが2回読み込まれてブラウザに送信されます。私は元の投稿を、自分のログが2回ロードされたときにどのように見えるのかを思いついた。 – aberrant