I'm having an issue where my CodeIgniter controllers are being called twice. It only seems to occur when I am using parameters in the uri (/newsletter/confirm/a1938cas893vf9384f0384f0943). If I remove the parameter from my function it only loads the controller once. I also noticed that with the parameter in the url, if I refresh the page it only loads once. So it seems that it is loading twice only when a new page is called.
For example navigating to /newsletter/confirm/a123 for the very first time will result in it loading twice. But if you were to refresh /newsletter/confirm/a123 it will only load once. I've completed commented out calls to my view to eliminate an issue with the view causing it.
Does this sound like a cache issue, or something in my .htaccess file? Thanks for any suggestions.
Relevant controller:
<?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 file:
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
Here's what the log file looks like, you can see everything is being reloaded twice:
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