【问题标题】:Silverstripe 3, ProductCatalog - friendly URL and Sub CategoriesSilverstripe 3,ProductCatalog - 友好的 URL 和子类别
【发布时间】:2014-07-21 02:45:04
【问题描述】:

我正在使用此 Silverstripe 模块创建产品目录:

https://github.com/luisdias/silverstripe-productcatalog 这是基于这个模块 https://github.com/arambalakjian/DataObject-as-Page

我有一个问题,友好的 URL 显示为:www.mysite.com/product-page/category/1 要么 www.mysite.com/product-page/show/1/1 与其标题或 url 段并列。 www.mysite.com/product-page/show/my-category/my-product

我尝试将代码从 Product.php 更改为

//Return the link to view this category
public function Link() {
    $Action = 'show/' . $this->ID . '/' . $this->URLSegment;
    return $Action;    
} 

来自

//Return the link to view this category
public function Link() {
    $Action = 'show/' . $this->ID . '/' . $this->CategoryID;
    return $Action;    
} 

这有效,但不适用于类别标题,并且 url 有空格,它会生成 %20 而不是 _。

这似乎是一个我无法解决的简单更改..


我还希望能够有子类别。因此,一个类别中的所有内容都可以分为它们的“大小”。目前所有产品只分一次。产品 > 类别 我想要 产品 > 类别 > 子类别 谁能帮我实现这一目标?谢谢

【问题讨论】:

  • Product Catalog 模块不是基于 DataObjectAsPage 模块的。

标签: php friendly-url silverstripe product catalog


【解决方案1】:

1) 对于 URL 中的空格问题:

URLSegment 是产品 DataObject 上的一个字段,它是在 CMS 中手动输入的,对吗?如果是这样,您必须输入 URLSegment 作为 URL 友好字符串,例如 my-awesome-product

如果您希望自动生成 URLsegment,请使用 DataObject As Page module you mentioned handles that。我会将该方法和关联的onBeforeWrite 方法添加到扩展ProductDataObject。您也许可以通过一些DataExtension 魔法来完成此操作。

2) 对于 URL issue 中的类别 URLSegment:

您还必须在 Category 类上重载 Link() 方法。您需要更改它(或在扩展 Category 的自定义 DataObject 中重载该方法):

$Action = 'category/' . $this->URLSegment;

然后像 #1 中那样添加 generateURLSegment 方法和 onBeforeWrite 调用。

【讨论】:

    猜你喜欢
    • 2016-03-24
    • 1970-01-01
    • 2013-01-15
    • 2015-02-27
    • 1970-01-01
    • 2019-02-21
    • 2011-05-08
    • 1970-01-01
    • 2010-10-18
    相关资源
    最近更新 更多