簡體   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