drt96856 2015-01-18 20:35
浏览 37

用两个var纠正函数调用

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';
  • 写回答

1条回答 默认 最新

  • duanqi6274 2015-01-18 20:49
    关注

    end active_links() with

    return(array($active1,$active2)); 
    

    then

    $active =  active_links(); 
    

    $active will be an array with 2 variables to use:

    $active[0] and $active[1]

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致