Cache problem
Permalink 2 users found helpful//get blocks from the $cobj's area $blocks = $cobj->getBlocks('Content'); //the desired block is always first in the area $b = $blocks[0]; $bi = $b->getInstance(); $content = $bi->getContent();
Everything works just fine until I enable cache on the site. On first page load everything is fine, but after the objects has been cached every page load gives the following error:
Fatal error: main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CaptionedContentBlockController" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /xxx/xxx.php on line 20
line 20 means the $bi->getContent();
Any idea?
What's the exact directory name of your custom block? They have to match exactly in terms of camelcasing vs. directories with underscores. That's how the autoloading knows where to find the block.
So, if your class is
MyCustomBlockController
your directory name will have to be
my_custom
If you name it MycustomBlockController
your directory name will have to be
mycustom
That was indeed my problem.
I really appreciate the detailed explanation.
Wondering: does making that change necessitate removing and reinstalling the block?
In my case, the class name is like:
MyCustomBlockController
and the directory is:
myCustom
The directory is obviously named in wrong manner, but how should I change the class name to make it point to the right directory? Or does the capital letter in dir name make it impossible? I wouldn't want to reinstall the block as it's being used all around the site.
Based on the answers given the first thing I would try is changing the class name to MycustomBlockController (if you haven't already).
Or you might look into how to do the __autoload thing.
The problem was obviously the wrong folder name. However, probably the easiest way to fix to problem was to rename the directory AND the put the same name to corresponding btHandle in the BlockTypes table.
Everything seems to work fine, including adding new blocks or modifying old ones.
I can add it to an Area, but if I put a block instance in edit mode and click "Update" (even without making any changes) I get the same error you described (mine points to concrete/startup/process.php, line 514).
This only happens if caching is turned on in sitewide settings / debug. If it's off, the block updates just fine.
I'm using 5.4 RC1.
I've seen this type of error elsewhere in the forums. Perhaps some benevolent knowledgeable person can point us in the right direction?