用两个var纠正函数调用

时间:2015-01-18 20:35:21

标签: javascript php jquery

我有php函数调用2个变量来控制活动链接。我不知道它是否正确写入以及如何在我的其他脚本中调用它。

我的功能在functions.php中,我的导航在nav.php中。我在index.php中都包含了这两个。

功能:

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';

1 个答案:

答案 0 :(得分:1)

使用

结束active_links()
return(array($active1,$active2)); 

然后

$active =  active_links(); 

$active将是一个包含2个变量的数组:

$active[0]$active[1]