dtr32787 2016-11-18 20:11
浏览 46
已采纳

从Php函数中检索数据

How to get data from php function? I want to call icon with:

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

Not work.

If it works would be like this

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

But if call another function like:

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

Work well.

Main php function:

/**
 * 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);
}

I want to call icon here, as I mark // Get Icon

                        <?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>

Did anyone have any ideas for this?

I really appreciate all the help.

  • 写回答

1条回答 默认 最新

  • dongmaxi6763 2016-11-18 20:50
    关注

    Well, this is working b

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

    because there is name attribute is very first base URI

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

    if you add icon as well, it will work

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

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 QTableWidget重绘程序崩溃
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding