Part of the EllisLab Network
   
 
[solved]Controller gets loaded twice and I do not know why
Posted: 06 September 2010 05:42 AM   [ Ignore ]  
Summer Student
Total Posts:  8
Joined  08-06-2010

In order to see the first page on the http://www.domain.tld address I have created an index.php controller file. The class is called Index and the views are called from the default Index() function defined in that class where I run the code that generates the content and call the views that will be shown on the first view.

In other words, I am loading the page from the default controller’s constructor.

The result of this is that the controller gets called twice and I find it easy to find why.

I have found somebody had a simmilar problem to mine but he gave no way to resolve this problem

http://codeigniter.com/forums/viewthread/156468/

My log file says the following

DEBUG - 2010-09-06 12:06:22—> Config Class Initialized
DEBUG - 2010-09-06 12:06:22—> Hooks Class Initialized
DEBUG - 2010-09-06 12:06:22—> URI Class Initialized
DEBUG - 2010-09-06 12:06:22—> No URI present. Default controller set.
DEBUG - 2010-09-06 12:06:22—> Router Class Initialized
DEBUG - 2010-09-06 12:06:22—> Output Class Initialized
DEBUG - 2010-09-06 12:06:22—> Input Class Initialized
DEBUG - 2010-09-06 12:06:22—> Global POST and COOKIE data sanitized
DEBUG - 2010-09-06 12:06:22—> Language Class Initialized
DEBUG - 2010-09-06 12:06:22—> Loader Class Initialized
DEBUG - 2010-09-06 12:06:22—> Controller Class Initialized
DEBUG - 2010-09-06 12:06:22—> URI:
DEBUG - 2010-09-06 12:06:22—> Helper loaded: url_helper
DEBUG - 2010-09-06 12:06:22—> Language file loaded: language/english/main_lang.php
DEBUG - 2010-09-06 12:06:22—> File loaded: /hiddenpath/system/application/views/head.php
DEBUG - 2010-09-06 12:06:22—> File loaded: /hiddenpath/system/application/views/menu.php
DEBUG - 2010-09-06 12:06:22—> File loaded: /hiddenpath/system/application/views/header.php
DEBUG - 2010-09-06 12:06:22—> File loaded: /hiddenpath/system/application/views/index.php
DEBUG - 2010-09-06 12:06:22—> File loaded: /hiddenpath/system/application/views/footer.php
DEBUG - 2010-09-06 12:06:22—> Controller Class Initialized
DEBUG - 2010-09-06 12:06:22—> URI:
DEBUG - 2010-09-06 12:06:22—> File loaded: /hiddenpath/system/application/views/head.php
DEBUG - 2010-09-06 12:06:22—> File loaded: /hiddenpath/system/application/views/menu.php
DEBUG - 2010-09-06 12:06:22—> File loaded: /hiddenpath/system/application/views/header.php
DEBUG - 2010-09-06 12:06:22—> File loaded: /hiddenpath/system/application/views/index.php
DEBUG - 2010-09-06 12:06:22—> File loaded: /hiddenpath/system/application/views/footer.php
DEBUG - 2010-09-06 12:06:22—> Final output sent to browser
DEBUG - 2010-09-06 12:06:22—> Total execution time: 0.0202

Profile
 
 
Posted: 06 September 2010 06:07 AM   [ Ignore ]   [ # 1 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3198
Joined  06-10-2007

.htaccess

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

Profile
 
 
Posted: 06 September 2010 06:13 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  8
Joined  08-06-2010

My .htaccess file says the following. Am I making something wrong here?

RewriteEngine on
RewriteCond $1 !^(index\.php|css|img|js|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

Profile
 
 
Posted: 06 September 2010 07:40 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  451
Joined  03-10-2007

Actually this doesn’t look at all like a .htaccess problem, that would cause the entire system to be loaded twice - not just the controller.

I think the problem is the name of the controller. “index” is a reserved name because it is also the name of the default function when a controller is loaded without a function set (see Reserved names in the User Guide).

What probably happens is that your index() function is loaded the first time as the class’s constructor and then a second time as the default function. As the Router is loaded in the parent constructor this probably causes the Router to be loaded twice as well, though I’d need to see your code to be sure.

You need to rename your controller to something different from “index” and remove parent::Controller() from the index() function, that should only be in the constructor not the index function.

 Signature 

Starting with CodeIgniter setup
Senior dev of FuelPHP | My open source CI 1.7 libs: AugmentedCI (CI package), MP_Cache (Partial caching), Ab_Wizard (create multi-page forms), FileXS (wraps & secures access), PageBuilder (OO templating) are all on BitBucket

Profile
 
 
Posted: 06 September 2010 12:00 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  8
Joined  08-06-2010

Jelmer your answer was the solution thanks I changed the name of the class and it worked as predicted.

Bye

Profile