繁体   English   中英

从Php函数检索数据

[英]Retrieve Data From Php Function

如何从PHP函数获取数据? 我想通过以下方式调用图标:

<i class="<?php $this->Html->_($value['icon']);?>"></i>

不行。

如果有效的话就是这样

<i class="fa fa-cloud"></i>

但是,如果调用另一个函数,例如:

<a href="#"><?php $this->Html->_($value['name']); ?></a>

做得好

主要的PHP功能:

/**
 * Retrieves the primary navigation for the client interface
 *
 * @param string $base_uri The base_uri for the currently logged in user
 * @return array An array of main navigation elements in key/value pairs
 *  where each key is the URI and each value is an array representing that element including:
 *     - name The name of the link
 *     - active True if the element is active
 *     - sub An array of subnav elements (optional) following the same indexes as above
 */
public function getPrimaryClient($base_uri)
{
    $nav = [
        $base_uri => [
            'name' => $this->_('Navigation.getprimaryclient.nav_dashboard'),
            'active' => false
        ],
        $base_uri . 'accounts/' => [
            'name' => $this->_('Navigation.getprimaryclient.nav_paymentaccounts'),
            'active' => false,
            'secondary' => [
                $base_uri . 'accounts/' => [
                    'name' => $this->_('Navigation.getprimaryclient.nav_paymentaccounts'),
                    'active' => false,
                    'icon' => 'fa fa-list'
                ],
                $base_uri . 'accounts/add/' => [
                    'name' => $this->_('Navigation.getprimaryclient.nav_paymentaccounts_add'),
                    'active' => false,
                    'icon' => 'fa fa-plus-square'
                ],
                $base_uri => [
                    'name' => $this->_('Navigation.getprimaryclient.nav_return'),
                    'active' => false,
                    'icon' => 'fa fa-arrow-left'
                ]
            ]
        ],
        $base_uri . 'contacts/' => [
            'name' => $this->_('Navigation.getprimaryclient.nav_contacts'),
            'active' => false,
            'secondary' => [
                $base_uri . 'contacts/' => [
                    'name' => $this->_('Navigation.getprimaryclient.nav_contacts'),
                    'active' => false,
                    'icon' => 'fa fa-list'
                ],
                $base_uri . 'contacts/add/' => [
                    'name' => $this->_('Navigation.getprimaryclient.nav_contacts_add'),
                    'active' => false,
                    'icon' => 'fa fa-plus-square'
                ],
                $base_uri => [
                    'name' => $this->_('Navigation.getprimaryclient.nav_return'),
                    'active' => false,
                    'icon' => 'fa fa-arrow-left'
                ]
            ]
        ]
    ];

    // Include the primary client's plugin navigation
    return $this->getPluginNavPrimaryClient($nav, $base_uri);
}

我想在这里调用图标,因为我标记为//获取图标

                        <?php
                        $active_nav = null;
                        ?>
                        <ul class="nav navbar-nav">
                            <?php
                            foreach ($this->Html->ifSet($nav, array()) as $link => $value) {
                                $attributes = array();
                                $link_attributes = array();
                                $dropdown = !empty($value['sub']);
                                $active = false;

                                if ($value['active']) {
                                    $active = true;
                                    $attributes['class'][] = "active";
                                    $active_nav = $value;
                                }
                                if ($dropdown) {
                                    $attributes['class'][] = "dropdown";
                                    $link_attributes['class'][] = "dropdown-toggle";
                                    $link_attributes['data-toggle'][] = "dropdown";

                                    // Set parent to active if child is
                                    if (!$active) {
                                        foreach ($this->Html->ifSet($value['sub'], array()) as $sub_link => $sub_value) {
                                            if ($sub_value['active']) {
                                                $attributes['class'][] = "active";
                                                break;
                                            }
                                        }
                                    }
                                }
                            ?>
                            <li<?php echo $this->Html->buildAttributes($attributes);?>>
                                <a href="<?php $this->Html->_($link);?>"<?php echo $this->Html->buildAttributes($link_attributes);?>>

            // Get Icon
                <i class="<?php $this->Html->_($value['icon']);?>"></i>
            // Get Icon 
                                    <?php
                                    $this->Html->_($value['name']);

                                    if ($dropdown) {
                                    ?>
                                    <b class="caret"></b>
                                    <?php
                                    }
                                    ?>
                                </a>
                                <?php
                                if (!empty($value['sub'])) {
                                ?>
                                <ul class="dropdown-menu">
                                    <?php
                                    foreach ($this->Html->ifSet($value['sub'], array()) as $sub_link => $sub_value) {
                                    ?>
                                    <li>
                                        <a href="<?php $this->Html->_($sub_link);?>"><i class="<?php $this->Html->_($sub_value['icon']);?>"></i> <?php $this->Html->_($sub_value['name']);?></a>
                                    </li>
                                    <?php
                                    }
                                    ?>
                                </ul>
                                <?php
                                }
                                ?>
                            </li>
                            <?php
                            }
                            ?>
                        </ul>

有人对此有任何想法吗?

我真的很感谢所有帮助。

好吧,这是可行的b

<i class="<?php $this->Html->_($value['name']);?>"></i>

因为有name属性是第一个基本URI

$base_uri => [
        'name' => $this->_('Navigation.getprimaryclient.nav_dashboard'),
        'active' => false
    ],

如果您还添加图标,它将起作用

$base_uri => [
        'name' => $this->_('Navigation.getprimaryclient.nav_dashboard'),
        'active' => false,
        'icon' => 'fa fa-cloud' 
    ],

希望这可以帮助。

暂无
暂无

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

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