Welcome Guest, Not a member yet? Register   Sign In
Going throw the Controller twice !
#1

[eluser]Unknown[/eluser]
Hello CI People,

I am Said, from France. I am a project leader and I am testing CI to see if we can used it in our campany.

I had some troubles to save some posted form data into database. I put some logs and I finally understood what was wrong with it : the controller is besing executed twice!
Is it really necessary to do that?
Thanks.

How to reproduce this problem :

If there some logs files, delete them

1- In the controller file, put this line in a class method :

Code:
log_message('debug','>>> Going throw the requested Controller Method <<<');

2- Open the controller url in your browser by pointing the class method One Time.

3- Open the log file, and you will see that this message is logged TWICE althought you requested the controller ONE TIME :gulp:

DEBUG - 2008-01-27 16:47:38 --&gt; Config Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Hooks Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Router Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Output Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Input Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; XSS Filtering completed
DEBUG - 2008-01-27 16:47:38 --&gt; Global POST and COOKIE data sanitized
DEBUG - 2008-01-27 16:47:38 --&gt; URI Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Language Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Loader Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Helpers loaded: url, var_dump
DEBUG - 2008-01-27 16:47:38 --&gt; Database Driver Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Config file loaded: config/application.php
DEBUG - 2008-01-27 16:47:38 --&gt; Controller Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; >>> Going throw the requested Controller Method <<<
DEBUG - 2008-01-27 16:47:38 --&gt; Model Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; File loaded: application/views/editeur.php
DEBUG - 2008-01-27 16:47:38 --&gt; File loaded: application/views/html_doc.php
DEBUG - 2008-01-27 16:47:38 --&gt; Language file loaded: language/english/profiler_lang.php
DEBUG - 2008-01-27 16:47:38 --&gt; Final output sent to browser
DEBUG - 2008-01-27 16:47:38 --&gt; Total execution time: 0.4139
DEBUG - 2008-01-27 16:47:38 --&gt; Config Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Hooks Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Router Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Output Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Input Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Global POST and COOKIE data sanitized
DEBUG - 2008-01-27 16:47:38 --&gt; URI Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Language Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Loader Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Helpers loaded: url, var_dump
DEBUG - 2008-01-27 16:47:38 --&gt; Database Driver Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Config file loaded: config/application.php
DEBUG - 2008-01-27 16:47:38 --&gt; Controller Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; >>> Going throw the requested Controller Method <<<
DEBUG - 2008-01-27 16:47:38 --&gt; File loaded: application/views/editeur.php
DEBUG - 2008-01-27 16:47:38 --&gt; File loaded: application/views/html_doc.php
DEBUG - 2008-01-27 16:47:38 --&gt; Language file loaded: language/english/profiler_lang.php
DEBUG - 2008-01-27 16:47:38 --&gt; Final output sent to browser
DEBUG - 2008-01-27 16:47:39 --&gt; Total execution time: 0.3651


QUESTION : Do You agree that this file should look like the following?

DEBUG - 2008-01-27 16:47:38 --&gt; Config Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Hooks Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Router Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Output Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Input Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; XSS Filtering completed
DEBUG - 2008-01-27 16:47:38 --&gt; Global POST and COOKIE data sanitized
DEBUG - 2008-01-27 16:47:38 --&gt; URI Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Language Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Loader Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Helpers loaded: url, var_dump
DEBUG - 2008-01-27 16:47:38 --&gt; Database Driver Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; Config file loaded: config/application.php
DEBUG - 2008-01-27 16:47:38 --&gt; Controller Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; >>> Going throw the requested Controller Method <<<
DEBUG - 2008-01-27 16:47:38 --&gt; Model Class Initialized
DEBUG - 2008-01-27 16:47:38 --&gt; File loaded: application/views/editeur.php
DEBUG - 2008-01-27 16:47:38 --&gt; File loaded: application/views/html_doc.php
DEBUG - 2008-01-27 16:47:38 --&gt; Language file loaded: language/english/profiler_lang.php
DEBUG - 2008-01-27 16:47:38 --&gt; Final output sent to browser
DEBUG - 2008-01-27 16:47:38 --&gt; Total execution time: 0.4139

QUESTION : IS it really necessary to go throq the controller twice?

NOTICE : there is no redirection in my code.

Thanks a lot every body.
#2

[eluser]tonanbarbarian[/eluser]
I use the debug logging all the time and I never come across this problem
I suggest the issue may be either your webserver config, or perhaps you having something in your code that is doing it but you do not realise it.

Are you using any CI reserved words for the name of your Controller, or for the names of methods in the controller?
Perhaps your .htaccess is incorrect and is causing the issue?
#3

[eluser]wiredesignz[/eluser]
Its actually running your entire application twice. Not just the controller.

Something weird there, its definitely a coding issue with your application.
#4

[eluser]isaiahdw[/eluser]
Are you using php 4?

If you are using php4, make sure you aren't using a reserved keyword
#5

[eluser]John_Betong[/eluser]
&nbsp;
&nbsp;
Bump
&nbsp;
&nbsp;
I am in the process of updating one of my sites.
&nbsp;
When the default Controller is loaded there is no problem but when a method is called in the Controller then I discovered that "Final output sent to browser", etc was also happening twice.
&nbsp;
I am using Wamp5 Ver: 2.0, PHP5, Windows XP.
&nbsp;
Anybody any updates on this problem?
&nbsp;
For those that like to check code:
Code:
// following Controller method called with either:
  // http://localhost/
  // or
  // http://localhost/blog/index/world-bank-to-clean-up-bangkok/231
  
  //==================================================
  function index($b_title='', $b_idx=9999) {

    // if no parameter is passed then a default/home page is called
    // for testing purposes $b_idx = 9999
    // this will call exactly the same code for the default/home page
    if (TRUE) {
      $b_idx = 9999; // forces default/home page
    }
        
    // No comments for default/home page
       $show_comments = ($b_idx != 9999);

    $this->view_001($data, $show_comments, $b_idx);
  }//endfunc index
&nbsp;
&nbsp;
#6

[eluser]Derek Jones[/eluser]
John, what's view_001()?
#7

[eluser]John_Betong[/eluser]
&nbsp;
Hi Derek,

View_001() is a common function (going through the design stages) and called upon by numerous contoroller methods:
&nbsp;
Controller Method - warts & all Smile
Code:
//==============================================
  function view_001($data=array(), $show_comments=TRUE, $b_idx=9999) {
    $data['comment_add']      = '';
    $data['comment_show']     = '';
    $data['comments_posted']  = '';
    
    $data['header']     = ''; // $this->load->view('_comment_add',        $data, TRUE);
    $data['title']      = "<h1 style='color:#f00'>title goes here</h1>";
    $data['blogtitle']  = 'blogtitle goes here';
    
    // maybe home/first page
    if (9999 == $b_idx) {
      $data['submit_blog']    = anchor('blog/article_submit/-1', 'Submit Your Article Here!', "style='color:#00f;'");
      $data['blogtitle']      = 'Welcome to Bankol&rsquo;s Expat Tales, Stories, Pictures, Information, News &amp; Titbits';
      $data['thelot']         = $this->load->view('_blog_intro', $data, TRUE);
    }else{  
      $data  =  $this->m_lib->m_getarticle($data, $b_idx);
      // $data['submit_blog'] = 'NOT REQUIRED';
      // $data['thelot']         = $this->load->view('_blog_intro', $data, TRUE);
      // $show_comments = FALSE;
      $data['b_idx']         = $b_idx;
      $data['cap_image']    = $b_idx;
      $data['XXX']         = $b_idx;
      
    }  

    $data['pagetitle']  = 'pagetitle goes here';

    // My_base Stuff
    if ($show_comments) {
        $data = $this->_comments($data, $b_idx);
        $thelot = array('thelot', 'thelot');

      $data['comment_add']      = $this->load->view('_comment_add',        $data, TRUE);
      $data['comments_posted']  = $this->comments_posted($data,            $data['idx']) ;
      $data['comment_show']     = $this->load->view('_comment_show',       $data, TRUE);
    }
    
    $data = $this->boxes($data); // lots of little boxes such as box_title, quotes, left_col, right_col, etc    
    // echo $data['submit_blog'];die;
    if (! TRUE) {
      $output = $this->load->view('welcome_message', $data, TRUE);
       }else{
      $output = $this->load->view('view_001', $data, TRUE);
    }  
    echo $output;
}//endfunc
&nbsp;
&nbsp;
#8

[eluser]Derek Jones[/eluser]
Well this method is calling other application methods as well, so I'm afraid it's not enough to go on. It's definitely something in your application, though. Strip everything out of that method and start adding things in piece by piece until the behavior starts again, is my recommendation. And, not related, but in your index method, you're sending $data but that variable isn't defined anywhere.
#9

[eluser]John_Betong[/eluser]
&nbsp;
Hi Derek,
&nbsp;
I will have a go tomorrow since it is quite late here. I will gradually reduce the calls to other helpers, libraries, models, etc and try to pinpoint the problem.
&nbsp;
What amazes me is the exact same View_001() method is called with the same parameters. the only difference is the method of calling the index() method. Weird to say the least. By the way the both outputs validate for all HTML and CSS errors.
&nbsp;
The point you made about sending the undefined $data value has also been noted. Fortunately in the View_001() method it does have a default. Definitely not good a good programming practise and will be rectified.
&nbsp;
&nbsp;
#10

[eluser]John_Betong[/eluser]
&nbsp;
Hi Derek
&nbsp;
I was very fortunate and managed to find the error by using the following:
Code:
log_message('debug','>>>>>>>>>>>> ' .$b_idx .' <<<<<<<<<<<<<<<<<<<<<<<<<<<');

The first result was 9999 as to be expeted but the next result was favicon.ico. I checked on the header and it showed an incorrect path to the icon. I also played about with the log_message(...) and placed it in various parts of the controller and only on a very few occassions the same error appear? Needless to say the HTML output validated OK. Maybe I should get a better validator.
&nbsp;
The start of all the problems was when I introduced Captcha. Four Captcha images were produced and also both CodeIgniter's Sessions and PHP's $_SESSION variables were returning incorrect results.
&nbsp;
The havoc an incorrect path to the favicon icon caused was unbelievable. What made it worse was the lack of error information.
&nbsp;
Today I introduced two link buttons at the bottom of my LOCALHOST output, one to delete amd the other to view the error logfile. I am curious to know how many others are oblivious that their applications are running more than once.
&nbsp;
Happiness is a single application run!
&nbsp;
&nbsp;
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB