【发布时间】: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