Welcome Guest, Not a member yet? Register   Sign In
[solved]Controller gets loaded twice and I do not know why
#1

[eluser]xare[/eluser]
In order to see the first page on the 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://ellislab.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
#2

[eluser]wiredesignz[/eluser]
.htaccess
#3

[eluser]xare[/eluser]
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]
#4

[eluser]Jelmer[/eluser]
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.
#5

[eluser]xare[/eluser]
Jelmer your answer was the solution thanks I changed the name of the class and it worked as predicted.

Bye




Theme © iAndrew 2016 - Forum software by © MyBB