Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CodeIgniter 3 html helper ul函数,如何将参数传递给li';s_Php_Css_Codeigniter_Zurb Foundation - Fatal编程技术网

Php CodeIgniter 3 html helper ul函数,如何将参数传递给li';s

Php CodeIgniter 3 html helper ul函数,如何将参数传递给li';s,php,css,codeigniter,zurb-foundation,Php,Css,Codeigniter,Zurb Foundation,我正在用CodeIgniter 3实现一个站点,并且我正在使用,它可以很好地满足我的需要。我的UL有以下阵列 $links = array( anchor(index_page(),"Home",(uri_string() == "" ? array('class' => 'active') : '')), anchor("about-us","About Us",(uri_string() == "about-us" ? array('class' => 'acti

我正在用CodeIgniter 3实现一个站点,并且我正在使用,它可以很好地满足我的需要。我的UL有以下阵列

$links = array(
    anchor(index_page(),"Home",(uri_string() == "" ? array('class' => 'active') : '')),
    anchor("about-us","About Us",(uri_string() == "about-us" ? array('class' => 'active') : '')),
    anchor("customers","Customers",(uri_string() == "customers" ? array('class' => 'active') : '')),
    anchor("policy","Policy",(uri_string() == "policy" ? array('class' => 'active') : '')),
    anchor("contact","Contact",(uri_string() == "contact" ? array('class' => 'active') : ''))
);

$attributes_normal = array(
    'id'    => 'main_menu'
);
因此,在使用这些阵列后,我将ul初始化为:

<?php echo ul($links, $attributes_normal); ?>

结果如下所示(关于我们的部分为示例打开):


这里我唯一的问题是,有没有办法将活动链接条件传递给
  • 元素。我使用ZURB基金会5,默认情况下,将<代码>类=“活动”< /代码>添加到<代码>
  • 元素,因此我想使用默认的CSS.< /P> < P>不重写默认的<>代码>列表> /COD>帮助器函数。在HTML帮助程序的源代码中,您可以看到“
  • ”是硬编码的,不接受其他参数:

    $out .= str_repeat(' ', $depth + 2).'<li>';
    
    $out.=str_repeat(“”,$depth+2)。

  • 我可能只是使用jQuery或JavaScript设置活动类,但您也可以选择覆盖默认的帮助函数来生成列表(请参见)。

    您必须在应用程序/帮助程序路径中创建MY_html_helper.php

    if ( ! function_exists('_list'))
    {
    /**
     * Generates the list
     *
     * Generates an HTML ordered list from an single or multi-dimensional array.
     *
     * @param   string
     * @param   mixed
     * @param   mixed
     * @param   int
     * @param   string
     * @param   string
     * @return  string
     */
    function _list($type = 'ul', $list = array(), $attributes = '', $depth = 0, $outer = '__outer', $inner = '__inner' )
    {
        // If an array wasn't submitted there's nothing to do...
        if ( ! is_array($list))
        {
            return $list;
        }
    
        // Set the indentation based on the depth
        $out = str_repeat(' ', $depth)
            // Write the opening list tag
            .'<'.$type._stringify_attributes($attributes).">\n";
    
    
        // Cycle through the list elements.  If an array is
        // encountered we will recursively call _list()
    
        static $_last_list_item = '';
        foreach ($list as $key => $val)
        {
            $_last_list_item = $key;
    
            if ( $key !== $outer && $key !== $inner) {
                $out .= str_repeat(' ', $depth + 2) . '<li ' . (is_array($val) && array_key_exists($outer, $val) ? _stringify_attributes($val[$outer]) : '') . '>';
                if (!is_array($val)) {
                    $out .= $val;
                } else {
                    $out .= $_last_list_item . "\n" . _list($type, $val, (array_key_exists($inner, $val) ? $val[$inner] : ''), $depth + 4) . str_repeat(' ', $depth + 2);
                }
                $out .= "</li>\n";
            }
    
        }
    
        // Set the indentation for the closing tag and apply it
        return $out.str_repeat(' ', $depth).'</'.$type.">\n";
    }
    }
    

    __内部和外部选项不会出现在列表中

    我明白了,我认为在这种情况下避免使用
    ul
    功能会更容易。谢谢
    if ( ! function_exists('_list'))
    {
    /**
     * Generates the list
     *
     * Generates an HTML ordered list from an single or multi-dimensional array.
     *
     * @param   string
     * @param   mixed
     * @param   mixed
     * @param   int
     * @param   string
     * @param   string
     * @return  string
     */
    function _list($type = 'ul', $list = array(), $attributes = '', $depth = 0, $outer = '__outer', $inner = '__inner' )
    {
        // If an array wasn't submitted there's nothing to do...
        if ( ! is_array($list))
        {
            return $list;
        }
    
        // Set the indentation based on the depth
        $out = str_repeat(' ', $depth)
            // Write the opening list tag
            .'<'.$type._stringify_attributes($attributes).">\n";
    
    
        // Cycle through the list elements.  If an array is
        // encountered we will recursively call _list()
    
        static $_last_list_item = '';
        foreach ($list as $key => $val)
        {
            $_last_list_item = $key;
    
            if ( $key !== $outer && $key !== $inner) {
                $out .= str_repeat(' ', $depth + 2) . '<li ' . (is_array($val) && array_key_exists($outer, $val) ? _stringify_attributes($val[$outer]) : '') . '>';
                if (!is_array($val)) {
                    $out .= $val;
                } else {
                    $out .= $_last_list_item . "\n" . _list($type, $val, (array_key_exists($inner, $val) ? $val[$inner] : ''), $depth + 4) . str_repeat(' ', $depth + 2);
                }
                $out .= "</li>\n";
            }
    
        }
    
        // Set the indentation for the closing tag and apply it
        return $out.str_repeat(' ', $depth).'</'.$type.">\n";
    }
    }
    
    $links = array(
        'Access Control' => array(
             'Users' => array(
                   '__outer' => array(
                        //Here you have the config for 'User' option 'li'
                        'class' => 'active some-class',
                        'id' => 'my-unique-id'
                   )
              ),
              'Roles',
              'Permissions',
              '__inner' => array(
                   //Here you have the config for inner ul (sub-menu)
                   'class' => 'sub-menu'
              ),
              '__outer' => array(
                   //Here you have the config for 'Access Control' option 'li'
                   'class' => 'active'
              ),
        ), 
    );