繁体   English   中英

遍历树枝中的多维数组

[英]Looping through multidimentional array in twig

我已经在php模型中创建了这个数组。 在下面。

$handle = opendir($this->path);

while(false !== ($file = readdir($handle)))
{
    if($file != "." && $file != "..")
    {
        $this->content[] = array(
            'name' => $file,
            'name_href' => $file,
            'extn' => $this->findExts($file),
            'file_size' => number_format(filesize($this->path . '/' . $file)),
            'mod_time' => date("M j Y g:i A", filemtime($this->path . '/' . $file)),
            'time_keys' => date("YmdHis", filemtime($this->path . '/' . $file))
        );
    }
}
closedir($handle);

而且我正试图用树枝环遍它。 但是页面没有显示任何内容。 但是,如果我使用print_r $content数组显示所有数据,那么我知道该数组不为空。 有人可以帮助我找出如何循环浏览并显示内容。

这是我尝试过的

{% for key, value in content %}
    <li>
       <a class="show_content" href="{{ value.name_href }}">{{ value.name }}</a>
    </li>
{% endfor %}

但这不会显示任何内容。 这是我将内容传递到树枝模板的地方。

$template = $twig->loadTemplate('layout.html.twig');
$template->display(array('content' => $content));

因此,问题不是循环。 运行正常。

问题是我没有正确地传递内容,我只是没有注意。 愚蠢的错误。

我有这个: $template->display($content);

它必须是这个$template->display(array('content' => $content));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM