我知道我们可以随机排序DataList以下内容:
$example = Example::get()->sort('RAND()');
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试随机排序时,ArrayList它不起作用.我可以在排序ArrayList的ID DESC,但不能用RAND().
有没有办法ArrayList随机对其项目进行排序?
例:
public function AllTheKits() {
$kits = Versioned::get_by_stage('KitsPage', 'Live');
$kitsArrayList = ArrayList::create();
foreach ($kits as $kit) {
if ($kit->MemberID == Member::currentUserID()) {
$kitsArrayList->push($kit);
}
}
return $kitsArrayList;
}
Run Code Online (Sandbox Code Playgroud)
在一个页面中:
public function getKitsRandom() {
return $this->AllTheKits()->sort('RAND()');
}
Run Code Online (Sandbox Code Playgroud)
这在带有的模板中不起作用 <% loop KitsRandom %>
我没有看到Silverstripe的任何备份脚本模块将数据库和资产文件夹导出到压缩文件夹中.有没有人有自定义PHP脚本并使用cron作业执行它?
我在使用PaginatedPages时遇到了麻烦.在文档中,可以自定义摘要.
有我的代码:
public function PaginatedPages($n = 10) {
$list = Page::get()->sort(array('Date' => DESC));
$Pages = new PaginatedList($list, $this->request);
if ($_GET['results'] != "") {
$n = $_GET['results'];
}
$Pages->setPageLength($n);
return $Pages;
}
Run Code Online (Sandbox Code Playgroud)
模板页面底部的分页:
<div id="PaginatedPages">
<% if $PaginatedPages.MoreThanOnePage %>
<% if $PaginatedPages.NotFirstPage %>
<a class="prev" href="$PaginatedPages.PrevLink"><</a>
<% end_if %>
<% loop $PaginatedPages.Pages %>
<% if $CurrentBool %>
<a class="current">$PageNum</a>
<% else %>
<% if $Link %>
<a href="$Link">$PageNum</a>
<% else %>
...
<% end_if %>
<% end_if %>
<% …Run Code Online (Sandbox Code Playgroud) Actualy,我正在使用扩展类中的代码.
示例:
class EcommerceEmail extends Email {
...
$from = SiteConfig::get()->first()->EcommerceDefaultEmail;
...
}
Run Code Online (Sandbox Code Playgroud)
我的问题是来自变量的$.它有效,但我不认为这是最好的主意.
我想到了这一点
$this->SiteConfig()->EcommerceDefaultEmail
Run Code Online (Sandbox Code Playgroud)
或这个
$this->owner->SiteConfig()->EcommerceDefaultEmail
Run Code Online (Sandbox Code Playgroud)
我的最后两个代码不起作用,我不知道为什么.还有另一种方法可以从子类中获取SiteConfig()中的EcommerceDefaultEmail吗?