Optimize informative page

3

I have a page that receives monthly information, to display the month that the user wants to do:

<a href="?mes=ago2015" class="list-group-item 
<?=($mes=='ago2015')?'active':''?>" id="ago2015">Agosto / 2015</a>  

And call the referring page with an include:

$mes = empty($_GET['mes'])?'infos':$_GET['mes'];

case 'ago2015': 
    include('infos/agosto2015.php');
break;

Does anyone suggest any better way to do this?

    
asked by anonymous 10.12.2015 / 10:33

1 answer

3

One way to optimize this would be to create an array the keys are the months and values the names of the files to do the include. The ideal was to keep these values in the bank.

<?php
    $informativos = [
                    'set/2015' => 'info/set2015',
                    'out/2015' => 'info/out2015',
                    'nov/2015' => 'info/nov2015',
                    'dez/2015' => 'info/dez2015',
                    'padrao'   => 'info/404.php'    
    ];


    $mes = empty($_GET['mes']) ? 'padrao' : $_GET['mes'];

    include_once $informativos[$mes] .'.php';
    
10.12.2015 / 11:45