SQL query executed 3 times (not wanted) |
[eluser]Jelenik[/eluser]
Hi guys, i am experiencing a strange behaviour. I want to insert one row to database everytime is shown detail of video. But sql query seems to be executed 3 times - in profiler there is only 1 sql. I tried everything - i tried to remove all code which i dont use - only problematic part remains. I simplified functions - for example that function $this->Hlavny->zvys_pocet_zobrazeni do more (it actually updates detail of video too, but thats not important - it creates duplicity sql queries with simplified version too). It seems that there are some redirects or something, because i am experiencing this only when my url ends with slash. Lets get to the point. My routes.php Code: $route['default_controller'] = "something"; - i tried to use new feature and force to use only that one controller through settings in main controller index.php - but it didnt work either - and i found that there is a error with example -> There is: The controller class file name. Example: Mycontroller.php -> but it didnt work with .php at the end for me - i dont know if it depends on server on which codeigniter runs or its only bug. I have this controller: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); $this->project->inicializacia() - this is simple inicialization function, which is used only for setting up meta tags + profiler as you can see Code: function inicializacia() I am using model Hlavny.php: Code: <?php I found that there are 2 similiar thread on this forum with this kind of issue (both arent resolved as you can see): http://ellislab.com/forums/viewthread/68585/ http://ellislab.com/forums/viewthread/64160/ Knows somebody where can be that problem? I have lost 2 hours trying everything in code and on the end i noticed that without slash on the end it works - but this is not solution.
[eluser]oldmatt[/eluser]
I don't know if this is your problem, but I have had problems in the past with routes because I was not careful about how I defined the routes. URI Routing That page in the documentation shows in the pink note box, that the order in which you define routes affects the results. Again, I didn't really extensively look into your code, but I thought it might be a good place to start.
[eluser]Jelenik[/eluser]
Oldmatt - thanks for reply - i think that it must be something with routing too, but if you look to my routes.php, there are only 2 rules: Code: $route['default_controller'] = "something"; - i dont see any problem there, so i dont know why the hell is this happening ![]()
[eluser]Jelenik[/eluser]
After many of hours trying everything, i think that i find where is problem. I had in view image with relative path(i just received design from designer and i didnt noticed that there is image with relative path - i am using absolute paths for images), so adding slash on the end will break that path. And when there is a problem with path for image - it creates duplicates sql queries - i think that it is very strange - or it is a feature? ![]() I have created bugtest application with which you can see yourself. You can download it here: http://bugtest.gigavideo.sk/script.zip Database structure + simple data here: http://bugtest.gigavideo.sk/bug_test.sql In application/database.php is set username as root and no password - assume that you want to test in on localhost - or you can just edit it for your needs as you wish. Maybe you will need to edit .htaccess - for example in XAMPP i have this .htaccess: Code: RewriteEngine On And on live server i have: Code: RewriteEngine On Or you can just test it live here: http://bugtest.gigavideo.sk/ Just try both variants which are offered - with slash on the end and without and then click on third link which will show you inserted rows for your IP...
[eluser]WanWizard[/eluser]
It's the downside of using 'lazy' rewrite rules. Your rules basically say "rewrite everything that isn't a file or a directory to index.php". Which means that every typo or missing asset will generate a second request of index.php. Store your assets in a separate /assets folder, and exclude that from rewriting to avoid issues like this.
[eluser]Jelenik[/eluser]
Thanks a lot WanWizard for clarification. Its shame that i forget to think about that redirects. But again thanks! |
Welcome Guest, Not a member yet? Register Sign In |