Jump to content

Custom Page Class recursion issue


FireWire
 Share

Recommended Posts

Hey all. I'm having an issue with the new custom page classes feature which is a fantastic tool.

I am running into a recursion issue when attempting to call a custom page class. I have a class called BlogPostPage.php (for blog-post.php) which contains a method called getSummary(). That method gets a summary field or truncates the body in it's absence. I've attached photos of the template code, custom page class code (which I've simplified for testing), and the PW output error.

There is no recursion in the getSummary() method. This error occurs whether I output multiple blog posts in a loop or if I output one blog post with no looping in my template code.

In use:
ProcessWire 3.0.164 dev
PHP 7.3.13

I am also using the Template Engine Twig module which has not caused any errors or issues thus far.

Many thanks!

blog_post_page_class.png

custom_page_class_error.png

custom_page_class_template_code.png

Link to comment
Share on other sites

Not quite sure what's causing the recursion error, but your method is marked private, which means it can't be called from outsite. Because your page class extends Page which extends Wire which comes with a magic __call method that will be invoked in this case. That method tries to figure out what you're trying to do, since it's supposed to provide easy access to properties and methods of all Wire extending objects. The error call stack indicates there's something going wrong there. Making your getSummary method public should fix the issue!

  • Like 5
  • Thanks 1
Link to comment
Share on other sites

5 minutes ago, MoritzLost said:

Not quite sure what's causing the recursion error, but your method is marked private, which means it can't be called from outsite. Because your page class extends Page which extends Wire which comes with a magic __call method that will be invoked in this case. There's probably something going wrong there. Making your getSummary method public might fix the issue!

Changing the method visibility fixed the issue. I don't know how I overlooked it.

This is officially the most embarrassing thing I've posted on any support board... ever. Ha! That was totally an accident as I've written other page classes and minded the private/public declaration.

Hope this ends up helping others!

Thanks!

  • Like 2
Link to comment
Share on other sites

It happens to all of us ?  This is actually why I dislike the use of the magic methods like __call, because they make tiny mistakes like this harder to spot ... without the magic, this would just result in a clear, easy to fix error message, but with it it's way harder to figure out what's going on.

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...