php function voor bootstrap sidebarmenu
ik was een php programmeur, ik ben een tijd erg ziek geweest daardoor ben ik een stuk geheugen kwijt zodat ik erg veel dingen zoals het programeren moeilijk kan omdat ik dat gedeelte bijna helemaal kwijt ben.
maar ik wil het weer oppakken daar ben ik nu een maand mee bezig alleen ik kom er maar niet uit, wat vroeger een makie was is nu erg moeilijk.
maargoed ik wil mijn cms om zetten in een bootstrap admin ik heb een admin template gekocht http://themeforest.net/item/pixit-admin-frontend-template/7528815 en die wil ik gaan gebruiken.
alleen kom ik er niet uit om de sidebar menu met submenus te maken met mijn php function, wie wil deze omzetten naar een werkende en daarbij vermelden hoe en wat het werkt.
dit is mijn function:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
//=======================================================================================================
function build_sidebar_menu( $id = 0, $div_id = ' class="sidebar-nav" ', $ul_sub = '', $level = 0 )
{
// global $Tpl;
if ( empty ( $this->my_array ))
return;
$my_array = $this->my_array;
if(count($my_array) < 1) return '';
$html = '<!-- vision_to_navigation (php class) sidebar - by www.vision.to -->' . $this->nl;
$html .= '<ul ' . $div_id . '>' . $this->nl;
foreach ( $this->my_array as $key => $node )
{
//if($this->get_sidebar ( $node['id'], $my_array, $level ))
if ( ( $node['active'] && $node['parent'] == 0 && $node['id'] == $id ) || ( $node['active'] && in_array( $node['id'], $this->active_path ) && $node['parent'] == 0 ))
{
$querystring = $this->format_url ($node['file_name']) ;
if ( isset ( $node['icon'] ))
{
// $html .= '<div class="menuicon"><img src="' . $node['icon'] . '" alt="' . $node['title'] . '"/></div>' . $this->nl;
}
$html .= '<li class="current">';
//$html .= '<a href="' . $querystring . '">' '" title="' . $node['title'] . '" >' . $node['title'] . '</a>';
$html .= '<a href="' . $querystring . '">' ;
$html .= '<i class="fa fa-dashboard"></i>';
$html .= '<span class="sidebar-text">' . $node['title'] .'</span></li>'. $this->nl;
$html .= $this->get_sidebar ( $node['id'], $my_array, $level+1 );
}
}
//$html .= '</li>' . $this->nl;
return $html;
}
//=======================================================================================================
function get_sidebar ( $el_id, $my_array, $level = 0, $expand = false, $expand_all = false)
{
// global $Tpl;
$selected = '';$expand_class = '';
if ( !is_array( $my_array ))
{
$my_array = $this->my_array;
}
if(count($my_array) < 1) return '';
$has_subcats = false;
$html = '';
//$html .= "".' <ul>' . "\n";
foreach ( $my_array as $key => $node )
{
if ( $node[ 'active' ] && $node[ 'parent' ] == $el_id )
{
$has_subcats = true;
if ( in_array( $node['id'], $this->active_path ) || $expand_all == true)
{
$expand = true;
}
else
{
$expand = false;
}
if($this->get_sidebar ( $node['id'], $my_array, $level ))
{$expand_class = ($expand == true ) ? 'open' : 'closed';}
$querystring = $this->format_url ($node['file_name']) ;
if ( in_array( $node['id'], $this->active_path ))
{
$selected = 'selected';
}
if ( $node['id'] == $this->get_file_id_eregi( ))
{
$selected = 'current';
}
$html .= ' <li>';
$link_class = (strlen($expand_class) || strlen($selected)) ? ' class="'.$expand_class.' '.$selected.'" ' : '';
// $description = (strlen($node['description']) >0) ?'<span class="tip">'.$node['description'].'</span>':'';
$html .= '<a ' . $link_class . ' href="' . $querystring . '" title="' . $node['title'] . '">' . $node['title'] .'</a>';
if($expand == true )
{
$html .= $this->get_sidebar ( $node['id'], $my_array, $level+1, $expand_all);
}
$html .= ' </li>' . "\n";
$selected = ''; $expand_class = '';
}
}
$html .= '</ul>'."\n";
// return ( $has_subcats ) ? '<div>'.$html.'</div>' : false;
return ( $has_subcats ) ? $html : false;
}
//===============================================================================================
?>
//=======================================================================================================
function build_sidebar_menu( $id = 0, $div_id = ' class="sidebar-nav" ', $ul_sub = '', $level = 0 )
{
// global $Tpl;
if ( empty ( $this->my_array ))
return;
$my_array = $this->my_array;
if(count($my_array) < 1) return '';
$html = '<!-- vision_to_navigation (php class) sidebar - by www.vision.to -->' . $this->nl;
$html .= '<ul ' . $div_id . '>' . $this->nl;
foreach ( $this->my_array as $key => $node )
{
//if($this->get_sidebar ( $node['id'], $my_array, $level ))
if ( ( $node['active'] && $node['parent'] == 0 && $node['id'] == $id ) || ( $node['active'] && in_array( $node['id'], $this->active_path ) && $node['parent'] == 0 ))
{
$querystring = $this->format_url ($node['file_name']) ;
if ( isset ( $node['icon'] ))
{
// $html .= '<div class="menuicon"><img src="' . $node['icon'] . '" alt="' . $node['title'] . '"/></div>' . $this->nl;
}
$html .= '<li class="current">';
//$html .= '<a href="' . $querystring . '">' '" title="' . $node['title'] . '" >' . $node['title'] . '</a>';
$html .= '<a href="' . $querystring . '">' ;
$html .= '<i class="fa fa-dashboard"></i>';
$html .= '<span class="sidebar-text">' . $node['title'] .'</span></li>'. $this->nl;
$html .= $this->get_sidebar ( $node['id'], $my_array, $level+1 );
}
}
//$html .= '</li>' . $this->nl;
return $html;
}
//=======================================================================================================
function get_sidebar ( $el_id, $my_array, $level = 0, $expand = false, $expand_all = false)
{
// global $Tpl;
$selected = '';$expand_class = '';
if ( !is_array( $my_array ))
{
$my_array = $this->my_array;
}
if(count($my_array) < 1) return '';
$has_subcats = false;
$html = '';
//$html .= "".' <ul>' . "\n";
foreach ( $my_array as $key => $node )
{
if ( $node[ 'active' ] && $node[ 'parent' ] == $el_id )
{
$has_subcats = true;
if ( in_array( $node['id'], $this->active_path ) || $expand_all == true)
{
$expand = true;
}
else
{
$expand = false;
}
if($this->get_sidebar ( $node['id'], $my_array, $level ))
{$expand_class = ($expand == true ) ? 'open' : 'closed';}
$querystring = $this->format_url ($node['file_name']) ;
if ( in_array( $node['id'], $this->active_path ))
{
$selected = 'selected';
}
if ( $node['id'] == $this->get_file_id_eregi( ))
{
$selected = 'current';
}
$html .= ' <li>';
$link_class = (strlen($expand_class) || strlen($selected)) ? ' class="'.$expand_class.' '.$selected.'" ' : '';
// $description = (strlen($node['description']) >0) ?'<span class="tip">'.$node['description'].'</span>':'';
$html .= '<a ' . $link_class . ' href="' . $querystring . '" title="' . $node['title'] . '">' . $node['title'] .'</a>';
if($expand == true )
{
$html .= $this->get_sidebar ( $node['id'], $my_array, $level+1, $expand_all);
}
$html .= ' </li>' . "\n";
$selected = ''; $expand_class = '';
}
}
$html .= '</ul>'."\n";
// return ( $has_subcats ) ? '<div>'.$html.'</div>' : false;
return ( $has_subcats ) ? $html : false;
}
//===============================================================================================
?>
ik hoop dat iemand mij hierbij wil helpen
Alvast bedankt.
- Aar -:
Gelieve in het vervolg bij code de [code][/code]-tags gebruiken.
Hier kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt!
Hier kan je meer lezen over de mogelijke opmaakcodes.
Alvast bedankt!
Gewijzigd op 21/08/2015 13:03:15 door - Ariën -
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function build_sidebar_menu( $div_container = ' class="main-menu" ', $div_id = ' id="topnav" ', $ul_id ='class="sidebar-nav" ', $nest = 0, $use_expand = true, $expand = true )
{
if ( empty ( $this->my_array ))
return;
$selected = '';
$arrow = '';
$active = '';
//$html = '<!-- vision_to_homepage (php class) dynamic menu - by www.visionto.nl -->' . "\n";
//$html .= '<div>' . "\n";
$html .= ' <div' . $div_container . '>' . "\n";
$html .= "\n" . '<ul ' . $ul_id . '>' . "\n";
foreach ( $this->my_array as $key => $node )
{
// if($this->add_titles == true)
// $html .= "\n".'<li><h3 class="headerbar" >'.$node[ 'name' ].'</h3></li>' . "\n";
if ( $node['active'] && $node['parent'] == 0 )
{
if ( $this->menu_titles == true )
$html .= "\n" . '<li><h3 class="headerbar" >' . $node['title'] . '</h3></li>' . "\n";
$subsign = ( $this->get_children_1( $node['id'] ) != false ) ? $this->subsign : '';
if ( strlen( $node['css'] ) || strlen( $subsign ))
$html .= '<li ' . $subsign;
// $html .= '<li class="' . $node[ 'css' ] . '">'.$subsign;
else
$html .= '<li ' . $subsign;
$querystring = $node['file_name'];
if ( in_array( $node['id'], $this->active_path ))
{
$selected = 'class="current" ';
//$expand = true;
}
if ( $node['id'] == $this->get_file_id_eregi( ))
{
$active = ' class="active" ';
$arrow = $this->arrow;
}
$html .= $selected . '>'. '<a href="' . $querystring .'"><span class="sidebar-text">' . $node['title'] . '</span>' . $arrow . '</a>' ;
$selected = '';
$arrow = '';
$active = '';
$html .= $this->get_children_1( $node['id'], $nest++ );
$html .= '</li>' . "\n";
}
}
$html .= "\n" . '</ul>' . "\n";
$html .= "\n" . '</div>';
return $html . "\n" . '</div>';
}
//==========================================================================================
function get_children_1( $id, $nest = 0, $ul_sub = '' )
{
if ( empty ( $this->my_array ))
return;
$selected = '';
$arrow = '';
$active = '';
$has_children = false;
$indent = '';
$tabify = $nest ? str_repeat( '\t', $nest ) . ' ' : '';
$html = '';
if ( $nest == 0 )
$html .= $ul_sub . "\n";
else
$html .= "\n" . '<ul class="submenu collapse">' . "\n";
foreach ( $this->my_array as $key => $node )
{
if ( $node['active'] && $node['parent'] == $id )
{
$has_children = true;
//found node
$add_class = ( $this->get_children_1( $node['id'] ) != false ) ? 'active' : '';
if ( strlen( $node['css'] ) || strlen( $add_class ))
$html .='<li class=' . $add_class;
// $html .= '<li class="' . $node[ 'css' ] . $add_class.'">';
else
$html .= '<li>';
//
$querystring = $node['file_name'];
if ( in_array( $node['id'], $this->active_path ))
{
$selected = ' class="selected" ';
}
if ( $node['id'] == $this->get_file_id_eregi( ))
{
$active = ' class="active" ';
$arrow = $this->arrow;
}
// $html .= '<a '.$selected.' href="' .$querystring.'" title="'.$node[ 'title' ].'" >'.$node[ 'title' ].'</a>'.$this->check_file_status($node[ 'file_name' ]).$arrow;
$html .= '<a ' . $selected . ' href="' . $querystring . '"><span class="sidebar-text">' . $node['title'] . '</span>' . $arrow . '</a>';
$selected = '';
$arrow = '';
$html .= $this->get_children_1( $node['id'], $nest++ );
$active = '';
$html .= '</li>' . "\n";
}
}
$html .= "\n" . '</ul>' . "\n";
return ( $has_children ) ? $html : false;
}
{
if ( empty ( $this->my_array ))
return;
$selected = '';
$arrow = '';
$active = '';
//$html = '<!-- vision_to_homepage (php class) dynamic menu - by www.visionto.nl -->' . "\n";
//$html .= '<div>' . "\n";
$html .= ' <div' . $div_container . '>' . "\n";
$html .= "\n" . '<ul ' . $ul_id . '>' . "\n";
foreach ( $this->my_array as $key => $node )
{
// if($this->add_titles == true)
// $html .= "\n".'<li><h3 class="headerbar" >'.$node[ 'name' ].'</h3></li>' . "\n";
if ( $node['active'] && $node['parent'] == 0 )
{
if ( $this->menu_titles == true )
$html .= "\n" . '<li><h3 class="headerbar" >' . $node['title'] . '</h3></li>' . "\n";
$subsign = ( $this->get_children_1( $node['id'] ) != false ) ? $this->subsign : '';
if ( strlen( $node['css'] ) || strlen( $subsign ))
$html .= '<li ' . $subsign;
// $html .= '<li class="' . $node[ 'css' ] . '">'.$subsign;
else
$html .= '<li ' . $subsign;
$querystring = $node['file_name'];
if ( in_array( $node['id'], $this->active_path ))
{
$selected = 'class="current" ';
//$expand = true;
}
if ( $node['id'] == $this->get_file_id_eregi( ))
{
$active = ' class="active" ';
$arrow = $this->arrow;
}
$html .= $selected . '>'. '<a href="' . $querystring .'"><span class="sidebar-text">' . $node['title'] . '</span>' . $arrow . '</a>' ;
$selected = '';
$arrow = '';
$active = '';
$html .= $this->get_children_1( $node['id'], $nest++ );
$html .= '</li>' . "\n";
}
}
$html .= "\n" . '</ul>' . "\n";
$html .= "\n" . '</div>';
return $html . "\n" . '</div>';
}
//==========================================================================================
function get_children_1( $id, $nest = 0, $ul_sub = '' )
{
if ( empty ( $this->my_array ))
return;
$selected = '';
$arrow = '';
$active = '';
$has_children = false;
$indent = '';
$tabify = $nest ? str_repeat( '\t', $nest ) . ' ' : '';
$html = '';
if ( $nest == 0 )
$html .= $ul_sub . "\n";
else
$html .= "\n" . '<ul class="submenu collapse">' . "\n";
foreach ( $this->my_array as $key => $node )
{
if ( $node['active'] && $node['parent'] == $id )
{
$has_children = true;
//found node
$add_class = ( $this->get_children_1( $node['id'] ) != false ) ? 'active' : '';
if ( strlen( $node['css'] ) || strlen( $add_class ))
$html .='<li class=' . $add_class;
// $html .= '<li class="' . $node[ 'css' ] . $add_class.'">';
else
$html .= '<li>';
//
$querystring = $node['file_name'];
if ( in_array( $node['id'], $this->active_path ))
{
$selected = ' class="selected" ';
}
if ( $node['id'] == $this->get_file_id_eregi( ))
{
$active = ' class="active" ';
$arrow = $this->arrow;
}
// $html .= '<a '.$selected.' href="' .$querystring.'" title="'.$node[ 'title' ].'" >'.$node[ 'title' ].'</a>'.$this->check_file_status($node[ 'file_name' ]).$arrow;
$html .= '<a ' . $selected . ' href="' . $querystring . '"><span class="sidebar-text">' . $node['title'] . '</span>' . $arrow . '</a>';
$selected = '';
$arrow = '';
$html .= $this->get_children_1( $node['id'], $nest++ );
$active = '';
$html .= '</li>' . "\n";
}
}
$html .= "\n" . '</ul>' . "\n";
return ( $has_children ) ? $html : false;
}
als ik nu deze function gebruik en ik kijk dan in de html dan ziet het er bijna het zelfde uit maar ik krijg niet bij alle subs een arrow en als ik op de link klik dan werkt de dropdown niet ...
er zit we een js function aan maar daar snap ik niks van hij laad hem in maar er gebeurd niks ?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
/* Toggle submenu open */
function toggleSidebarMenu() {
var $this = $('.sidebar-nav');
$this.find('li.active').has('ul').children('ul').addClass('collapse in');
$this.find('li').not('.active').has('ul').children('ul').addClass('collapse');
$this.find('li').has('ul').children('a').on('click', function (e) {
e.preventDefault();
$(this).parent('li').toggleClass('active').children('ul').collapse('toggle');
$(this).parent('li').siblings().removeClass('active').children('ul.in').collapse('hide');
});
}
function toggleSidebarMenu() {
var $this = $('.sidebar-nav');
$this.find('li.active').has('ul').children('ul').addClass('collapse in');
$this.find('li').not('.active').has('ul').children('ul').addClass('collapse');
$this.find('li').has('ul').children('a').on('click', function (e) {
e.preventDefault();
$(this).parent('li').toggleClass('active').children('ul').collapse('toggle');
$(this).parent('li').siblings().removeClass('active').children('ul.in').collapse('hide');
});
}
volgens mij ben ik wel op de goede weg nu maar nu zit ik echt vast.
Edit:
Codetags geplaatst. Zie ook de Meest Gestelde Vragen op deze site.
Gewijzigd op 02/09/2015 20:18:27 door - Ariën -