树枝从数组循环

时间:2018-10-13 17:07:59

标签: php twig

我与树枝的php连接有问题。我在树枝中的for循环中看不到来自php的数据。

我在php中有数组:

Array
(
    [pageHeader] => Array
        (
            [pageMetatags] => Array
                (
                    [kwTitle] => domain.pl 
                    [kwDescription] => domain.pl 
                    [kwKeywords] => domain.pl 
                    [kwContentType] => text/html; charset=UTF-8
                    [kwRobots] => noindex
                    [kwRevisit] => none
                    [kwCopyrights] => domain.pl
                    [kwGooglebot] => noindex:
                    [kwPublisher] => domain.pl
                )

            [messageBox] => 
            [developerName] => dam
            [developerUrl] => http:/www.domain.pl
            [baseHref] => http:/localhost/
            [pageValue] => Array
                (
                    [mainCategoryUrl] => /CompaniesList
                    [subMainCategoryUrl] => 
                    [pageName] => Lista firm
                    [actualPageNumber] => 1
                    [sortAfter] => 
                    [searchString] => 
                    [pagination] =>     <nav aria-label="Page navigation">
        <ul class="pagination justify-content-center pagination-separate pagination-flat pagginationTopPadding">
                            <li class="page-item disabled">
                    <a class="page-link" href="#" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
                                        <li class="page-item active"><a class="page-link" href="#">1</a></li>
                                            <li class="page-item">
                            <a class="page-link" href="http:/localhost/CompaniesList?page=2&">2</a>
                        </li>
                                                <li class="page-item">
                            <a class="page-link" href="http:/localhost/CompaniesList?page=3&">3</a>
                        </li>
                                        <li class="page-item">
                    <a class="page-link" href="http:/localhost/CompaniesList?page=2&" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
                        </ul>
    </nav>

                    [dataTable] => Array
                        (
                            [0] => Array
                                (
                                    [enable] => 1
                                    [name] => 2
                                    [nip] => 
                                    [date_of_registration] => 0000-00-00 00:00:00
                                )

                            [1] => Array
                                (
                                    [enable] => 1
                                    [name] => 3
                                    [nip] => 
                                    [date_of_registration] => 0000-00-00 00:00:00
                                )

                            [2] => Array
                                (
                                    [enable] => 1
                                    [name] => 4
                                    [nip] => 
                                    [date_of_registration] => 0000-00-00 00:00:00
                                )

                        )

                )

        )

)

我想在树枝中的for循环中显示来自数组的数据 这是我的树枝代码:

{% for data in pageTemplate.pageHeader.pageValue.dataTable %}

                                    <tr>
                                        <th scope="row">
                                            <div class="icheck2 skin">
                                                <fieldset>
                                                    <input type="checkbox" name="" value="1" checked>
                                                    <label class="main-name-list-form">{{ pageTemplate.pageHeader.pageValue.dataTable.name }}</label>
                                                </fieldset>
                                            </div>
                                        </th>
                                        <td>Mark</td>
                                        <td>Otto</td>
                                        <td>
                                            <div class="btn-group">
                                                <button type="button" class="btn btn-success dropdown-toggle mr-1 mb-1"
                                                        data-toggle="dropdown"
                                                        aria-haspopup="true" aria-expanded="false">Info
                                                </button>
                                                <div class="dropdown-menu">
                                                    <a class="dropdown-item" href="#">Action</a>
                                                    <a class="dropdown-item" href="#">Another action</a>
                                                    <a class="dropdown-item" href="#">Something else here</a>
                                                    <div class="dropdown-divider"></div>
                                                    <a class="dropdown-item" href="#">Separated link</a>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                    {% endfor %}

我不知道为什么,但是我看不到名字:( 此行不起作用:

{{pageTemplate.pageHeader.pageValue.dataTable.name}}

有人知道如何解决吗?

1 个答案:

答案 0 :(得分:0)

dataTable是0索引数组,不具有name属性。但是它的每个子数组都具有此属性,所以我想您需要此代码(因为data代表datatTable的每一项):

<label class="main-name-list-form">{{ data.name }}</label>