0

I met some trouble with a function.

In fact I would like to include all my pages, but the thing is that not all pages are named like the param $_GET['page'] for example if I call index.php?p=accueil it will redirect to php/home.php

an other example if I call index.php?p=message it will redirect transparently to message.php

For all exceptions I've generated an array like that:

<?php    
$paramListepages = array(       
     'corbeille' => array(
         'libelle'     => 'corbeille',
         'page'        => 'php/trash.php'
     ),   
     'nouveaumessage' => array(
         'libelle'     => 'nouveaumessage',
         'page'        => 'php/envoyer.php'
     )  
);
?>

This array contain many sub_arrays As you can see the 2 firsts of this one.

For calling pages I've done a function like that:

function getPage($var) {
    if (!isset($var)){
        //Aucune page spécifiée => default page
        inlude('php/accueil.php');
    }
    elseif (array_key_exists($var,$paramListepages)){
        // page trouvée => on l'inclut!
        include ('php/accueil.php');
    }
    else{
        // page espectant la structure, non trouvée dans l'array => on l'inclut directement
        include('php/'.$var.'.php');    
    }
}

actualy it seems to recognise the if condition and the else.

But when I ask for a page in the array, there is a blank page It seems to not be able to read the correct value expected.

I have white empty pages with no mistake or message error.

In my Ubuntu I've activated the error_reporting(E_ALL);

Any kind of help will be much appreciated

René Höhle
  • 26,716
  • 22
  • 73
  • 82
Stanislas Piotrowski
  • 2,595
  • 10
  • 40
  • 59
  • Interesting, the way you changed my code I answered your previous question with. Interesting cause you broke it by exchanging the last two include statements. – arkascha Nov 19 '12 at 10:45
  • 1
    And why do you insist on the `isset()` at the start? $var is declared as function argument, it is impossible it dies _not_ exist there. You want to use `empty()`, as I suggested. – arkascha Nov 19 '12 at 10:47
  • actualy it does not work with the previous version and when I validated your code I was not able to change it – Stanislas Piotrowski Nov 19 '12 at 10:48
  • What does "not work" mean? Track down what page actually gets called by looking at the servers log files. No sense in _guessing_ what might happen. – arkascha Nov 19 '12 at 10:48
  • @arkascha You don't want to use `empty` either, since `empty` is `!isset($var) || !$var`. Just use `!$var`. – deceze Nov 19 '12 at 10:49
  • In fact for the first and the else it works, but when It check in the array it give me an empty page – Stanislas Piotrowski Nov 19 '12 at 10:49
  • An empty page might be an error in the script like that the included file is not found. So dump the file anme to be included AND CHECK THE LOG FILES (error log). Most likely you have the path level mixed up. – arkascha Nov 19 '12 at 10:50
  • @deceze: though it is fine what you explain I don't see why I don't want to use `empty()`. It is a question of being able to easily understand the meaning. – arkascha Nov 19 '12 at 10:52
  • Actualy in my ubuntu there is no log files, moreover I've tried to print or return the value of $paramListepages[$var]['page'] in order to see if it is correct but it always display blank page – Stanislas Piotrowski Nov 19 '12 at 10:53
  • What do you mean there is no log file? If ubuntu is really that stupidly preconfigured (which I doubt) then enable logging! You need it anyway! – arkascha Nov 19 '12 at 10:53
  • @arkascha Please refer to http://kunststube.net/isset. You want to avoid using the *error suppressing* constructs `isset` and `empty` whenever possible. – deceze Nov 19 '12 at 10:53
  • it is not generated, I've checked all the file in my trunk, but there is nothing like that. How can I activite it ? is it on the http.conf? – Stanislas Piotrowski Nov 19 '12 at 10:53
  • The server log files are not inside your application. It is _server log files_. Check your servers configuration where the log files are written to. Most likely something like `/var/log/apache2` or `/var/log/httpd`. Believer me, there _are_ log files. And they are of great value for you. Find them! Also it might help to turn on error display for debugging purposes, then error messages from php are shown inside your browser. THough you should turn that off again for production purposes. You can do that inside the `php.ini` configuraton file. – arkascha Nov 19 '12 at 10:55
  • Also for dumping values this is of great help: `syslog(LOG_DEBUG,'some string to dump');` and watch the log file that stuff is written to using `tail -f /var/log/messages` in some terminal emulator. That way the debug output does not interfere with your web UI. `yakuake` is a great terminal emulator for such purposes. – arkascha Nov 19 '12 at 10:58
  • Actualy it return this Mon Nov 19 11:56:09 2012] [error] [client 192.168.2.11] PHP Warning: include(): Failed opening 'php/voir_fiche_employee.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /mnt/getcash-trunk/GESTION/library/ so it mean that it does not check in the array because this value is in the array that should open its own page – Stanislas Piotrowski Nov 19 '12 at 11:00

1 Answers1

0

So basically this?

elseif (array_key_exists($var,$paramListepages)){
    include ($paramListepages[$var]['page']);
}
Sammitch
  • 30,782
  • 7
  • 50
  • 77