0

We're working with the php-based CMS Kirby but are having trouble understanding where we can (and can't) use chaining (we're pretty green when it comes to php).

We have a product section like this:

|_Shop
  |_Sheets
    |_Sheet one
    |_Sheet two
  |_Bed spreads
    |_Bed spread one
    |_Bed spread two

And are trying to deliver a list of all the product child pages under each category.

How do we do this?

We keep seeing a lot of "Call to a member function on a non-object" errors which we're assuming has to do with the way we're chaining things - e.g. we've tried many ways of doing this but are currently trying:

$productPages = $pages->findByDirname('sheets, duvet-covers, bed-spreads, pillowcases, table-linen');

But are unsure how to find the children of these pages as adding ->visible()->children() either to the end of $pages above or into the foreach loop like this results in errors:

<?php foreach($productPages->visible()->children() as $pageList) : ?>

Also, we can see that the $page variable has the ->visible()->children() variables so assume we need to hand our $productPages variable over to the $page variable so we can use visible()->children() but are unsure how to construct things sorry.

Any pointers in the right direction would be much appreciated.

Cheers

CMSCSS
  • 2,076
  • 9
  • 28
  • 49

1 Answers1

1

The reason you get Call to a member function on a non-object errors when you use $productPages->visible()->children() is because $productPages doesn't contain any page results.

I think that is because you are using findByDirname - i don't believe this takes a list like that. And if it does, that function requires using the number too.

You will be better of using $pages->find($uri, [$anotherUri]) which takes the uri path, rather than the dirname.

Or alternatively $pages->findByUID('sheets', 'bed-spreads', 'pillowcases') which is the dirname but without the number.

Check out the kirby cheatsheet - http://getkirby.com/content/02-docs/kirby-cheatsheet.pdf

Hope that moves you in the right direction.

rob_james
  • 1,262
  • 1
  • 12
  • 17