Php 是否有SS4.3代码在自定义主页模板上显示Silvershop特色产品

Php 是否有SS4.3代码在自定义主页模板上显示Silvershop特色产品,php,silverstripe-4,silvershop,Php,Silverstripe 4,Silvershop,我正在尝试为自己创建一个Silvershop站点,但当前建议在另一个模板页面上显示特色产品的代码在SS4.3上不起作用。我是否需要添加其他代码以使建议的代码在较新的silverstripe 4中工作 这是我一直在使用的资源: 在这一过程中,我不得不做一些调整,在大多数情况下,我已经设法让它工作,但我不知道如何调整这段代码,使其工作 class IndexPageController extends PageController { } /** * Get all products marked

我正在尝试为自己创建一个Silvershop站点,但当前建议在另一个模板页面上显示特色产品的代码在SS4.3上不起作用。我是否需要添加其他代码以使建议的代码在较新的silverstripe 4中工作

这是我一直在使用的资源: 在这一过程中,我不得不做一些调整,在大多数情况下,我已经设法让它工作,但我不知道如何调整这段代码,使其工作

class IndexPageController extends PageController {
}

/**
* Get all products marked as featured that can be purchased.
*/

class IndexPageController extends ProductCategory_Controller   {

   function FeaturedProducts()
   {
       return Product::get()->filter(array(
           'Featured' => 1
           'AllowPurchase' => 1
       ));
   }
}

该页面显示错误消息“当前无法处理此请求。”

数组中缺少逗号:

function FeaturedProducts()
    {
        return Product::get()->filter(array(
            'Featured' => 1,
            'AllowPurchase' => 1
       ));
   }
还要确保您使用的是Product类

use SilverShop\Page\Product;
在模板中:

<% if $FeaturedProducts %>

                        <% loop $FeaturedProducts %>
                                $Title
                        <% end_loop %>


            <% end_if %>

$Title

我尝试了其他类似问题的解决方案,但仍然无法在我的自定义InExpage上显示最新产品。函数FeaturedProducts(){$ProductCategory=\\silvershop\core\src\Page\ProductCategory Controller::get()->filter('Featured'=>1'AllowPurchase'=>1)->first();if(!$ProductCategory){return null;}$Product=$ProductCategory->Product()->sort('PublishDate',DESC');}有人有什么想法我可以试试吗?在我的silverstripe themes/app目录中,我找不到任何其他有助于解决将最新产品添加到我的自定义模板上的问题的来源。我需要在yml文件中包含一行吗?具有以下内容:公共函数FeaturedProducts(){$Product=\SilverShop\Model\Product\OrderItem::get()->filter(['Featured'=>1,'AllowPurchase'=>1])->First();$controller=\SilverShop\core\Page\ProductCategoryController::create();$ProductCategory=$Product->ProductCategory()->排序('PublishDate','DESC');返回$Product;}我收到以下错误消息:[紧急情况]未捕获的SilverStripe\ORM\Connect\DatabaseException:无法运行查询:选择不同的“SilverShop\u OrderAttribute”。“ClassName”,“SilverShop\u OrderAttribute”。“LastEdited”,“SilverShop\u OrderAttribute”。“Created”,“SilverShop\u OrderAttribute”。“CalculatedTotal”、“SilverShop\u OrderAttribute”、“OrderID”、“SilverShop\u OrderItem”、“Quantity”、“SilverShop\u OrderItem”、“UnitPrice”、“SilverShop\u Product\u OrderItem”、“ProductVersion”、“SilverShop\u Product\u OrderItem”、“ProductID”、“SilverShop\u OrderAttribute”、“ID”,当“SilverShop\u OrderAttribute”、“ClassName”不为空时,则为“SilverShop\u OrderAttribute”““ClassName”ELSE'SilverShop\\Model\\OrderAttribute”结尾为“RecordClassName”,来自“SilverShop\u OrderAttribute”上的“SilverShop\u OrderItem”左键加入“SilverShop\u OrderItem”。“ID”=“SilverShop\u OrderAttribute”中的“SilverShop\u OrderItem”。“ID”其中(“特色”=?)和(“AllowPurchase”=?)和(“SilverShop_OrderAttribute.”Clas