Welcome Guest, Not a member yet? Register   Sign In
Some classes load twice!
#1

[eluser]Razican[/eluser]
Hello, I'm trying to work with JQuery and CodeIgniter 2.0 (latest rev. in repo.) I have logs on, and have noticed that some classes load twice. Moreover, I'm doing an AJAX request and the result changes even if I'm not requesting it. For example, If I request a query, with num_rows() = 1, it starts to blink the 1 after finishing the request. But the main problem is the double loading. I have separated each request for you to see it better.

Code:
DEBUG - 06-12-2010 20:31:40 --> Config Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Hooks Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Unicode Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Unicode Class - UTF-8 Support Enabled
DEBUG - 06-12-2010 20:31:40 --> URI Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Router Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Output Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Input Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Security Class Initialized
DEBUG - 06-12-2010 20:31:40 --> XSS Filtering completed
DEBUG - 06-12-2010 20:31:40 --> XSS Filtering completed
DEBUG - 06-12-2010 20:31:40 --> CRSF cookie Set
DEBUG - 06-12-2010 20:31:40 --> Global POST and COOKIE data sanitized
DEBUG - 06-12-2010 20:31:40 --> Language Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Loader Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Config file loaded: megapublik/config/megapublik.php
DEBUG - 06-12-2010 20:31:40 --> Helper loaded: language_helper
DEBUG - 06-12-2010 20:31:40 --> Helper loaded: form_helper
DEBUG - 06-12-2010 20:31:40 --> Helper loaded: html_helper
DEBUG - 06-12-2010 20:31:40 --> Helper loaded: url_helper
DEBUG - 06-12-2010 20:31:40 --> Helper loaded: cookie_helper
DEBUG - 06-12-2010 20:31:40 --> Helper loaded: overal_helper
DEBUG - 06-12-2010 20:31:40 --> Language file loaded: language/spanish/overal_lang.php
DEBUG - 06-12-2010 20:31:40 --> Database Driver Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Session Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Helper loaded: string_helper
DEBUG - 06-12-2010 20:31:40 --> Encrypt Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Session routines successfully run
DEBUG - 06-12-2010 20:31:40 --> Model Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Model Class Initialized
DEBUG - 06-12-2010 20:31:40 --> Controller Class Initialized
Code:
DEBUG - 06-12-2010 20:31:46 --> Config Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Hooks Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Unicode Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Unicode Class - UTF-8 Support Enabled
DEBUG - 06-12-2010 20:31:46 --> URI Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Router Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Output Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Input Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Security Class Initialized
DEBUG - 06-12-2010 20:31:46 --> XSS Filtering completed
DEBUG - 06-12-2010 20:31:46 --> XSS Filtering completed
DEBUG - 06-12-2010 20:31:46 --> CRSF cookie Set
DEBUG - 06-12-2010 20:31:46 --> Global POST and COOKIE data sanitized
DEBUG - 06-12-2010 20:31:46 --> Language Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Loader Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Config file loaded: megapublik/config/megapublik.php
DEBUG - 06-12-2010 20:31:46 --> Helper loaded: language_helper
DEBUG - 06-12-2010 20:31:46 --> Helper loaded: form_helper
DEBUG - 06-12-2010 20:31:46 --> Helper loaded: html_helper
DEBUG - 06-12-2010 20:31:46 --> Helper loaded: url_helper
DEBUG - 06-12-2010 20:31:46 --> Helper loaded: cookie_helper
DEBUG - 06-12-2010 20:31:46 --> Helper loaded: overal_helper
DEBUG - 06-12-2010 20:31:46 --> Language file loaded: language/spanish/overal_lang.php
DEBUG - 06-12-2010 20:31:46 --> Database Driver Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Session Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Helper loaded: string_helper
DEBUG - 06-12-2010 20:31:46 --> Encrypt Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Session routines successfully run
DEBUG - 06-12-2010 20:31:46 --> Model Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Model Class Initialized
DEBUG - 06-12-2010 20:31:46 --> Controller Class Initialized
DEBUG - 06-12-2010 20:31:47 --> Model Class Initialized
DEBUG - 06-12-2010 20:31:47 --> File loaded: megapublik/views/registration/result.php
DEBUG - 06-12-2010 20:31:47 --> Final output sent to browser
DEBUG - 06-12-2010 20:31:47 --> Total execution time: 2.0412
DEBUG - 06-12-2010 20:31:48 --> Model Class Initialized
DEBUG - 06-12-2010 20:31:48 --> File loaded: megapublik/views/registration/result.php
DEBUG - 06-12-2010 20:31:48 --> Final output sent to browser
DEBUG - 06-12-2010 20:31:48 --> Total execution time: 2.0402
DEBUG - 06-12-2010 20:31:48 --> Model Class Initialized
DEBUG - 06-12-2010 20:31:48 --> File loaded: megapublik/views/registration/result.php
DEBUG - 06-12-2010 20:31:48 --> Final output sent to browser
DEBUG - 06-12-2010 20:31:48 --> Total execution time: 2.0357

The Model class loads twice, or even more times. On the other hand, the XSS Filtering loads also twice. How can I solve it?
#2

[eluser]WanWizard[/eluser]
Do you have a rewrite rule in place that rewrites everything that does not exist to index.php (the famous -f and -d rules)?

If you, you might have an asset missing (image, js file, etc), that causes a second rewrite to index.php.
#3

[eluser]Razican[/eluser]
This is my .htaccess file:

Code:
# Deny OR Allow Folder Indexes.
# Since we disable access to PHP files you
# can leave this on without worries.
# OR better yet, create a .htaccess file in
# the dir you want to allow browsing and
# set it to +Indexes
Options -Indexes

Options +FollowSymLinks

# Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /megapublik/

    # You can also uncomment this if you know the IP:
    # Deny from 192.168.1.1

    # If the file is NOT the index.php file
    RewriteCond %{REQUEST_FILENAME} !index.php
    # Hide all PHP files so none can be accessed by HTTP
    RewriteRule (.*)\.php$ index.php/$1

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^megapublik.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

It worked fine with CodeIgniter 1.7.2, and with the first rev.s in the repo. 2.0.
#4

[eluser]WanWizard[/eluser]
As I said, the famous -d and -f rules:
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
This means that all requests for non-existing files will be rewritten. So if, somewhere on your page, you have used "Image.jpg", but the file is called "image.jpg" (note the case difference), the request http://website/Image.jpg is rewritten to index.php, causing a second request.

As I've repeated here over and over again: DO NOT USE THIS!

Instead, create an assets folder, and store all your assets in there, then exclude that entire folder from rewriting. Better a 404 on an asset, than this (which can take hours and hours of work to discover the error).
#5

[eluser]Razican[/eluser]
I don't know much about .htaccess. I have my images in /images folder, javascript in /javascript and css in /css. How can I exclude them?
#6

[eluser]WanWizard[/eluser]
This should work
Code:
RewriteCond $1 !^(images|javascript|css)
#7

[eluser]Razican[/eluser]
I have changed the .htaccess file to look like this:

Code:
# Deny OR Allow Folder Indexes.
# Since we disable access to PHP files you
# can leave this on without worries.
# OR better yet, create a .htaccess file in
# the dir you want to allow browsing and
# set it to +Indexes
Options -Indexes

Options +FollowSymLinks

# Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /megapublik/

    # You can also uncomment this if you know the IP:
    # Deny from 192.168.1.1

    # If the file is NOT the index.php file
    RewriteCond %{REQUEST_FILENAME} !index.php
    # Hide all PHP files so none can be accessed by HTTP
    RewriteRule (.*)\.php$ index.php/$1

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^megapublik.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond $1 !^(images|javascript|css)
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

But now I get a 404 error every time.
#8

[eluser]WanWizard[/eluser]
Maybe in your case $1 sould be %{REQUEST_URI} (you seem to need that in all other conditions).
#9

[eluser]Razican[/eluser]
It doesn't work with %{REQUEST_URI}... I don't know what could be the problem...
#10

[eluser]WanWizard[/eluser]
I can't look into your environment, so it's very difficult for me to give you the correct config.

What you can do as a temporary measure, add
Code:
log_message('debug', "URL requested: ".$_SERVER['REQUEST_URI']);
as last statement of the constructor in system/core/controller.php. Make sure to set the log_threshold to 4 in your config to be able to see debugging.

It will log every URL requested to the log file. That would help you to find which assets are missing.




Theme © iAndrew 2016 - Forum software by © MyBB