I’m trying to make a function for including pages.
In fact For the beginning I used to work with a long code that checked for all pages:
if (isset($_GET]['p']) && $_GET['p']=='something') {include 'something.php'};
Now I work with more than 600 pages and this code is too long and I would like to simplify it.
Sometimes I do have pages that are note entitled like they are used, for example home will correspond to accueil.php etc.
So I’ve done an array in which I listed all exceptions:
like that:
$paramListepages = array(
'corbeille' => array(
'libelle' => 'corbeille',
'page' => 'php/trash.php'
),
'nouveaumessage' => array(
'libelle' => 'nouveaumessage',
'page' => 'php/envoyer.php'
),
etc…
In this array I have about 20 pages.
Now I’ve tried to create a function for including pages so here is my code:
function getPage($var)
{
if (isset($var)) {
$key = array_search($var, $paramListepages);
if ($key == false()) {
include('php/'.$var.'.php');
} else {
}
}
}
I do not understand why the first part does not work.
I first of all check if the var does exist in the array, if not I include the page corresponding to the var.
I do still do not know how to do the second part, but for now the first one does not work.
I have no message error, even if in my ubunto I activated the displaying of all errors.
In the main page index.php I call the function getPage($_GET['p'])
Any kind of help will be much appreciated.
I’d suggest accessing the entries in your array directly: