SilverStripe 3-<%循环%>的选项; [英] SilverStripe 3 - Options for <% loop %>

查看:64
本文介绍了SilverStripe 3-<%循环%>的选项;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在可以添加到循环中的所有选项的列表?

Is there a list of all the options I can add to a loop?

我不知道选项是否是正确的名称.我是说这些

I don't know if options is the right name for it. I mean these

<% loop Dataobject.Reverse %>
<% loop Dataobject.Limit() %>

有人可以告诉我在这里可能发生的一切吗?正确的名称是什么?

Can someone tell me everything that's possible here? And what the correct name for it is?

推荐答案

您的问题中有一个错误,它是<% loop $DataList.xxx %><% loop $ArrayList.xxx %>(请参见,您正在循环一个DataObjects列表)

there is an error in your question, it is <% loop $DataList.xxx %> or <% loop $ArrayList.xxx %> (see, you are looping a list of DataObjects)

嗯,loop基本上只是一个foreach循环

well, loop is basically just a foreach loop

例如,

<% loop $DataList.Reverse %>$Title<% end_loop %>

有点像:

<?php 
foreach($dataList->reverse() as $item) { 
    echo $item->Title; 
}

'kindof'相同,因为实际上模板为您进行了一些检查和强制转换(例如,如果未设置Title,它不会抛出错误),并且循环只能循环SilverStripe列表,而不是数组

'kindof' the same, because in fact the template does some checking and casting for you (eg it does not throw and error if Title is not set), and a loop can only loop SilverStripe lists, not arrays

tl; dr; /结论

tl;dr; / the conclusion

loop完全没有选项
您所说的选项是您要循环使用的列表中存在的方法. 您通常会循环的2个列出的php类是:

loop has no options at all
the options that you speak of are methods that exist on the list that you want to loop. the 2 lists php classes that you would normally loop are:

  • DataList api docs for class DataList
  • ArrayList api docs for class ArrayList

请参阅API文档中的方法列表,以了解可用的方法.

see the list of methods in the API docs for what methods are available.

显然,并非所有方法都打算用于循环,
只有返回DataListArrayList的那些才有用.
您可以从表格的第一栏中看到它们返回的内容.

obviously not all methods are meant to be used to loop,
only those that return a DataList or ArrayList will be useful.
you can see what they return from the first column of the table.

例如:

public ArrayList limit( integer $length, integer $offset = 0 )

表示:

  • 它是公共的(因此其可访问的,私有的或受保护的模板将无法在模板中使用)
  • 它返回ArrayList
  • 名称是limit
  • 参数是数字长度和数字偏移量
  • it is public (so its accessable, private or protected ones will not be available in template)
  • it returns ArrayList
  • the name is limit
  • the parameters are a number length and an number offset

因此您可以这样做:<% loop $List.limit(10,5) %>

进一步阅读:

该列表中的某些方法没有显示参数,但实际上有参数,这是因为它们是动态的,API文档无法显示该参数.

some methods in that list do not show parameters but actually do have them, this is because they are dynamic and the API docs fail to display that.

示例:

public ArrayList filter( )

可以这样使用(我认为,从未尝试过):

can be used like this (I think, never tried it):

<% loop $List.filter('Name', 'Zauberfisch') %>


您还可以通过创建Extension并将此扩展添加到DataListArrayList


you can also add your own methods by creating an Extension and adding this Extension to DataList and ArrayList

这篇关于SilverStripe 3-&lt;%循环%&gt;的选项;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆