【问题标题】:SilverStripe 3: How to display the URL Segment / Page info of a DataObjectSilverStripe 3:如何显示数据对象的 URL 段/页面信息
【发布时间】:2015-11-13 03:29:28
【问题描述】:

我从一个特定的类中获取我的所有数据对象,并在另一个页面上随机显示它们。我需要访问它们所属页面的 URL 段。我该怎么做呢? 我已经尝试过 $URLSegment $UP.URLSegment $Parent.URLSegment 等,我可以看到它们为什么不起作用。我意识到数据对象没有自己的 URL。我只需要其页面的 URL,因为这是它的类别。

PHP函数:

function Stockists()
{
$stockists = Stockist::get()->sort('RAND()');
return $stockists ? $stockists : false;
} 

模板

<% loop $Stockists %>
   $Title
   $URLSegment (does not work)
<% end_loop %>

【问题讨论】:

  • 我假设 Stockist 是数据对象而不是页面正确?与被称为页面的关系是什么?您的 Stockist 课程中是否有私有 $has_one=array('Page'=>'Page') 或类似的?

标签: php templates url silverstripe data-objects


【解决方案1】:

感谢马克·吉恩。 原来我可以使用

$StockistArea.URLSegment

因为是 Stockist 是数据对象类,并且有一个

 private static $has_one = array(
    'StockistArea' => 'StockistArea'
); 

到 StockistArea 页面!希望这会对某人有所帮助,因为我在上面找不到任何东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-20
    相关资源
    最近更新 更多