I am working on a Laravel 4 application that is configured to use the file
$_SESSION
driver, which appears to be causing some problems for me. The problem arises randomly, and does not happen very often, and tends to happen when I try and click on an <a href="...">
quickly before the entire page is done loading (there is a large amount of information loaded on each page so page loads can be a bit slow). The error will also appear at times after waiting for the page to load completely.
Here is the error message I'm getting:
From what I understand, it looks like whenever my application decides it wants to load a (cached?) view from app/storage/views
, it is not is not grabbing one or more of the objects that is passed to the view from my controller, and that is why I am getting a non-object error message.
I have tried experimenting by deleting the specific storage view in both the controller before the view is loaded and in the actual view itself (in app/views
) with the following:
<?php
$badFile1 = storage_path() . '/views/d84ddef7152ff1956fc7aa87ddf29ba0';
if(file_exists($badFile1))
{
$delete = unlink($badFile1);
}
?>
But even this will still throw the error (although without showing the line #) from the file in app/storage/views
, even though the file doesn't even exist:
Can anyone explain why this is happening and/or what I can do to fix this problem?
i thing you $catalog
object is null. so not called getID()
method.
Please check, $catalog
object is assigned or not.
I've managed to fix the problem, as in, I have not been able to reproduce this random error message anymore.
It seems the error was caused by getting my models code tangled up, and not by $catalogs
being null
. I had two models:
Suggestions.php
which does some data manipulation and Catalogs.php
which ultimately fetches the $catalogs
object which I needed for my view.
I was grabbing $catalogs
like this in my controller:
$s = new Suggestions();
$catalogs = $s->getSuggestions($catalogID);
and then returning $catalogs
in my view. The problem arises from the fact that I was also calling the Catalogs.php
model (which contains the getID()
function) from within the Suggestions.php
model, and was not even instantiating a new instance of Catalogs
to do so, just calling it straight away.
So most of the time Laravel would return $catalogs
as an object of the Catalogs
model like I wanted it to, but it would sometimes return it as an object of the Suggestions
model, and when my view tried to call the getID()
method, it was trying to call a method that did not exist in Suggestions
model.
I fixed this by refactoring the Suggestions
model into a private function as opposed to the model, that way $catalogs
is always returning as the Catalogs
object type.