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:

//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 &quot;CaptionedContentBlockController&quot; 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?

 
kirkroberts replied on at Permalink Reply
kirkroberts
I'm having a similar problem with a custom block.

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?
andrew replied on at Permalink Best Answer Reply
andrew
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
kirkroberts replied on at Permalink Reply
kirkroberts
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?
andrew replied on at Permalink Reply
andrew
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.
Ale replied on at Permalink Reply
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.
mose replied on at Permalink Reply
mose
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.
kirkroberts replied on at Permalink Reply
kirkroberts
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.
Ale replied on at Permalink Reply
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.