Ok, this is not a code snippet article. It’s just an experience which you probably already met, but it was nightmare to find and it took me 1/2 a day to fix this “stupid” bug.
So what is the case?
Working on a project including some advanced JavaScript and Ajax techniques my coworker Milen noticed that the Session is not behaving as expected. In a simple function like:
function test($id = false){
if ($id != false) {
echo $id;
echo $k = $this->Session->read('some_var');
$this->Session->write('some_var', $id);
}
$this->set('tests', $this->paginate());
}
The result should be quite easy to be predicted: if you pass for example 5 on the second reload the $k should be with the same value as $id. Unfortunately instead of 5 the $k was ‘images’. Yep, quite strange, isn’t it?
if you put die() at the end of the function, the result is as expected.
What was the problem
In our current project we are using jQuery and some of it’s plugins. So the problems was in the ThickBox plugin. If you remove it from the header everything works.
Digging into unpacked version of the plugin we’ve noticed that the loading picture is not where it should be. there is an variable
var tb_pathToImage = "images/loadingAnimation.gif"
and as you may notice the path is not compatible with Cake convention and obviously it’s not in the http://server/cakeapp/tests/test/images/.
In the example above we were writing id into the session. Yes but calling: http://server/cakeapp/tests/test/images/loadingAnimation.gif mean that $id take value of ‘images’.
It was quite tricky, because if you loading CSS or JavaScript and the file is not there, FireBug or even the html /if there is no correct CSS the styling will fail/ will warn the developer, but image loaded into the JS function is quite difficult to find.
Anyway, the conclusion is “Watch you JavaScript libs and what files they require”.