Problem in passing value by URL

0

I'm trying to create a more dynamic way of loading the pages I'm using, loading files as CSS only on one page, and from that page, call the others. However, I can not receive the value I'm passing through the URL. Here is the shipping code:

<div id='navbar' class='navbar-collapse collapse'>
<ul class='nav navbar-nav'>
    <li class='dropdown'>
        <a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='0false'>Ofícios<span class='caret'></span></a>
        <ul class='dropdown-menu'>
            <li class='dropdown'>
                <a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'>Funcionário<span class='caret'></span></a>
                <ul class='dropdown-menu'>
                    <li><a href='funcionario_cadastrar.php?link=17'>Cadastrar</a></li>                      
                    <li><a href='funcionario_listar.php?link=18'>Listar</a></li>
                    <li><a href='funcionario_consultar.php?link=19'>Consultar</a></li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

And receiving:

$link = $_GET["link"];
print_r($_GET["link"]);
if(isset($_GET["link"])){
    /*
    $pagina[17] = "funcionario_cadastrar.php";
    $pagina[18] = "funcionario_listar.php";
    $pagina[19] = "funcionario_consultar.php";

    if(!empty($link)){
        if(file_exists($pagina[$link])){
            include $pagina[$link];
        }else{
            include "bem_vindo.php";
        }
    }else{
        include "bem_vindo.php";
    }
}else{
    include "bem_vindo.php";
    */
}
    
asked by anonymous 22.08.2017 / 16:04

2 answers

1
<div id='navbar' class='navbar-collapse collapse'>
<ul class='nav navbar-nav'>
    <li class='dropdown'>
        <a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='0false'>Ofícios<span class='caret'></span></a>
        <ul class='dropdown-menu'>
            <li class='dropdown'>
                <a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'>Funcionário<span class='caret'></span></a>
                <ul class='dropdown-menu'>
                    <li><a href='index.php?link=17'>Cadastrar</a></li>                      
                    <li><a href='index.php?link=18'>Listar</a></li>
                    <li><a href='index.php?link=19'>Consultar</a></li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

if( isset($_GET["link"])){

  $link = $_GET["link"];
  switch ($link) {
        case 17:
            include="tema17.php";
            break;
        case 18:
            include="tema18.php";
            break;
        case 19:
            include="tema19.php";
            break;
        default:
            include="temaDefault.php";
            break;
    }
}

This is what I do to include files according to the value of the variable, redirects to the same page that in your case can be an index.php and inside it you put this code and so you include as many as you want. >

This creates a single menu, header, and footer.

    
22.08.2017 / 16:56
1

Try this way. I ran tests and it worked.

<?php
if(isset($_GET["link"]) && $_GET["link"] != '') {
    $link = $_GET["link"];

    switch ($link) {
        case 17:
            echo "funcionario_cadastrar.php"; //include "funcionario_cadastrar.php";
        break;
        case 18:
            echo "funcionario_listar.php"; //include "funcionario_listar.php";
        break;
        case 19:
            echo "funcionario_consultar.php"; //include "funcionario_consultar.php";
        break;
        default:
            echo "index.php"; //include "index.php";
        break;
    }
} else {
    echo "index.php"; //include "index.php";
}
    
22.08.2017 / 19:14