0

我们正在使用基于 php 的 CMS Kirby,但无法理解我们可以(和不能)使用链接的地方(在 php 方面我们非常环保)。

我们有一个这样的产品部分:

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

并试图提供每个类别下所有产品子页面的列表。

我们如何做到这一点?

我们不断看到很多“在非对象上调用成员函数”错误,我们假设这些错误与我们链接事物的方式有关——例如,我们已经尝试了很多方法,但目前正在尝试:

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

但是不确定如何找到这些页面的子页面,因为添加->visible()->children()到上面的末尾$pages或添加到 foreach 循环中,这样会导致错误:

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

此外,我们可以看到 $page 变量具有->visible()->children()变量,因此假设我们需要将$productPages变量交给$page变量,以便我们可以使用visible()->children()但不确定如何构造东西抱歉。

任何指向正确方向的指针都将不胜感激。

干杯

4

1 回答 1

1

Call to a member function on a non-object使用时出现错误的原因$productPages->visible()->children()是因为$productPages不包含任何页面结果。

认为那是因为您正在使用findByDirname- 我不相信这需要这样的列表。如果是这样,该功能也需要使用该数字。

你会更好地使用$pages->find($uri, [$anotherUri])which 采用 uri 路径,而不是 dirname。

或者$pages->findByUID('sheets', 'bed-spreads', 'pillowcases'),哪个是目录名但没有数字。

查看柯比备忘单 - http://getkirby.com/content/02-docs/kirby-cheatsheet.pdf

希望这能让你朝着正确的方向前进。

于 2014-02-28T11:44:53.257 回答