I have php function calling 2 variables for controlling active links. I don't know is it written correctly and how to call it in my other script.
My function is in functions.php and my navigation is in nav.php. I includ both in index.php.
Function:
function active_links() {
// stranice = Active //
if (isset($_GET['poslovni_korisnici'])) {
$active1 = 'class="active"';
} else {
$active1 = '';
}
if (isset($_GET['korisnici'])) {
$active2 = 'class="active"';
} else {
$active2 = '';
}
}
nav.php
<body>
<!-- start body -->
<nav class="navbar navbar-default">
<!-- start nav -->
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">POSLOVNA STATISTIKA</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li ' . $active . '><a href="index.php?poslovni_korisnici">Poslovni korisnici <span class="sr-only">(current)</span></a>
</li>
<li ' . $active . '><a href="index.php?korisnici">Korisnici</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
index.php:
<?php
require_once 'functions.php';
$dbh = connect_to_database();
$active = active_links();
include 'includes/head.php';
include 'includes/nav.php';