Welcome Guest, Not a member yet? Register   Sign In
Form loads multiple functions
#1

[eluser]Unknown[/eluser]
Hello,

I'm having some trouble with a controller/form. It seems that often when I send something with my form, CI will first load whatever function the form is set to send to, and then it'll load the function it was sent from (looks like the site is refreshed just after being sent, received, printed to screen).

I'm sure I must be doing something wrong, though not sure what.

controller: main.php

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Main extends CI_Controller {

function __construct()
{
  ## Call the model constructor
  parent::__construct();
  $this->output->enable_profiler(TRUE);
}

/**
  * Main
  *
  * Maps to URL:
  *  http://example.com/index.php/
  * and
  *  http://example.com/index.php/main/
  *
  */

public function index() {

  $data['main_content'] = 'main';
  $this->load->view('includes/template.php', $data);

}

/**
  * Records
  *
  * Maps to URL:
  *  http://example.com/index.php/main/records/
  *
  */
public function records() {
  log_message('debug', '----------------- loaded records()');
  $this->load->model('Data_list');

  $data['records'] = $this->Data_list->get_records();
  
  $data['main_content'] = 'records';
  $this->load->view('includes/template.php', $data);
}

public function insert_record()
{
  log_message('debug', '----------------- loaded insert_record()');
  die(var_dump($_POST));

}

}

The above should dump whatever is in the $_POST, right? It does almost every other time (sometimes it seems more random).


Log file showing that after insert_record() is loaded, it'll reload records(), look at the debug log messages:

Code:
DEBUG - 2012-11-01 10:38:29 --> Config Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Hooks Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Utf8 Class Initialized
DEBUG - 2012-11-01 10:38:29 --> UTF-8 Support Enabled
DEBUG - 2012-11-01 10:38:29 --> URI Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Router Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Output Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Security Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Input Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Global POST and COOKIE data sanitized
DEBUG - 2012-11-01 10:38:29 --> Language Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Loader Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Helper loaded: url_helper
DEBUG - 2012-11-01 10:38:29 --> Helper loaded: form_helper
DEBUG - 2012-11-01 10:38:29 --> Database Driver Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Controller Class Initialized
DEBUG - 2012-11-01 10:38:29 --> ----------------- loaded insert_record()
DEBUG - 2012-11-01 10:38:29 --> Config Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Hooks Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Utf8 Class Initialized
DEBUG - 2012-11-01 10:38:29 --> UTF-8 Support Enabled
DEBUG - 2012-11-01 10:38:29 --> URI Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Router Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Output Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Security Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Input Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Global POST and COOKIE data sanitized
DEBUG - 2012-11-01 10:38:29 --> Language Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Loader Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Helper loaded: url_helper
DEBUG - 2012-11-01 10:38:29 --> Helper loaded: form_helper
DEBUG - 2012-11-01 10:38:29 --> Database Driver Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Controller Class Initialized
DEBUG - 2012-11-01 10:38:29 --> ----------------- loaded records()
DEBUG - 2012-11-01 10:38:29 --> Model Class Initialized
DEBUG - 2012-11-01 10:38:29 --> Model Class Initialized
DEBUG - 2012-11-01 10:38:29 --> File loaded: application/views/includes/header.php
DEBUG - 2012-11-01 10:38:29 --> File loaded: application/views/records.php
DEBUG - 2012-11-01 10:38:29 --> File loaded: application/views/includes/footer.php
DEBUG - 2012-11-01 10:38:29 --> File loaded: application/views/includes/template.php
DEBUG - 2012-11-01 10:38:29 --> Language file loaded: language/english/profiler_lang.php
DEBUG - 2012-11-01 10:38:29 --> Helper loaded: text_helper
DEBUG - 2012-11-01 10:38:29 --> Final output sent to browser
DEBUG - 2012-11-01 10:38:29 --> Total execution time: 0.0163

What am I doing wrong?

Seems it loads functions several times as long as there are more than one in a controller, this is normal behaviour? because it says final output to browser, feels like it shouldn't..




Theme © iAndrew 2016 - Forum software by © MyBB