Cache problem
Permalink 2 users found helpful
I have a page list that loads blocks from another page. The blocks that are being loaded are custom blocks, which are basically just "normal" content blocks with two added textfields. The logic inside page_list goes something like this:
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?
//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 class name of the PHP class inside your custom block's controller?
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
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
Thank you, Andrew!
That was indeed my problem.
I really appreciate the detailed explanation.
Wondering: does making that change necessitate removing and reinstalling the block?
That was indeed my problem.
I really appreciate the detailed explanation.
Wondering: does making that change necessitate removing and reinstalling the block?
If you had to change the class name, it shouldn't matter. If you had to change the actual directory handle you'll probably want to uninstall/reinstall.
Good to see that there's an solution. The site that has the problem has gone live already (with cache off...). I just want to make sure one thing before modifying anything to keep the downtime as short as possible.
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.
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.
I believe the capital letter in the directory name makes it impossible. Directory names should be all lowercase. Because of the mapping between CamelCase and underlines, there is no way to name the class to match the directory myCustom.
Depends on the rules for how c5 produces its camel case. Maybe c5 lowercases everything before camel-casing it? You could look in the core to find out.
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.
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.
A little addition to this one:
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.
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?