遍历pyrocms模板变量中的数组
我已经调整了文件插件来列出所有文件夹,并在其中列出所有文件。
代码或多或少像这样:
$folders = assoc_array_prop($this->file_folders_m->get_all());
$counter = 1;
foreach ($folders as $key => $folder) {
$folder->index = str_pad($counter++, 2, '0', STR_PAD_LEFT);
$this->file_m->where('folder_id', $folder->id);
$files = $this->file_m->get_all();
$folder->files = assoc_array_prop($files);
}
return $folders;
现在,问题是,如何访问模板中每个文件夹的每个 $folder->files ?这似乎不起作用:
{pyro:mymod:file_listing}
<div class="files_column">
<h2><span class="files-index">{index}</span> {name}</h2>
{pyro:files}
<div class="file-item">
<span class="file-type">{id}</span>
<div class="file-data">
<span>{filename}</span>
<br/>
<span class="file-links">
<a href="#">View</a>
<a href="#">Download</a>
</span>
</div>
</div>
{/pyro:files}
</div>
{/pyro:mymod:file_listing}
为了澄清这一点......根据我看到数据出现的次数,{files}循环似乎工作正常。问题是我似乎无法访问它的属性,例如 {filename}。
谢谢, 伊格纳西奥
I've adapted the File plugin to list all folders and inside of them list all files.
The code is more or les like this:
$folders = assoc_array_prop($this->file_folders_m->get_all());
$counter = 1;
foreach ($folders as $key => $folder) {
$folder->index = str_pad($counter++, 2, '0', STR_PAD_LEFT);
$this->file_m->where('folder_id', $folder->id);
$files = $this->file_m->get_all();
$folder->files = assoc_array_prop($files);
}
return $folders;
Now, the thing is, how can I access each $folder->files for each folder in the template? This doesn't seem to work:
{pyro:mymod:file_listing}
<div class="files_column">
<h2><span class="files-index">{index}</span> {name}</h2>
{pyro:files}
<div class="file-item">
<span class="file-type">{id}</span>
<div class="file-data">
<span>{filename}</span>
<br/>
<span class="file-links">
<a href="#">View</a>
<a href="#">Download</a>
</span>
</div>
</div>
{/pyro:files}
</div>
{/pyro:mymod:file_listing}
To clarify on this... the {files} loop seems to work ok, based on the number of times I see the data appear. The problem is that I can't seem to acces its attributes, like {filename}.
Thanks,
Ignacio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你做错的第一件事是使用内部的pyro标签{pyro:files},我很确定它只会调用核心pyro:files插件。
我所做的一种遍历形式在标签中似乎不可能实现,那就是使用外部标签的属性来查找内部标签的信息:
像这样:
所以我使用当前元素中的 movie_id 来获取另一块来自我的插件的数据。我的插件有一个 now_showing 和一个 synopsis_snippet 函数。
您可以做的是使用一种列出文件夹的方法和一种列出文件夹的文件的方法,如下所示:
希望这会有所帮助。 :)
first thing I think you're doing wrong is having the inner pyro tag {pyro:files} which I'm pretty sure will just call the core pyro:files plugin.
What I did to do a form of traversing that didn't otherwise seem possible with tags was to use attributes of the outer tag to find information for the inner tag:
like this:
so I used the movie_id from the current element to get another piece of data from my plugin. My plugin has a now_showing and a synopsis_snippet function.
What you could do is have a method that lists folders and one that lists files of a folder something like this:
Hope this helps. :)