Jump to content

Quick Question


Shaun13

Recommended Posts

do you want the url to change in the browser? or just make the default action-> action=index ?

 

if(isset($_GET['action'])){
  $action = $_GET['action'];
}else{
  $action = 'index';
}

 

though you must be careful with this, depending on how your includes load

you should make an array of all available pages like so

 

$page = array(
    'index' => 'home.php',
    'page1' => 'page1.php',
    'page2' => 'page2.php');

if(isset($_GET['action'])){
  $action = $_GET['action'];
}else{
  $action = 'index';
}

if(in_array($action, $pages)){
  include('INCLUDE_PATH'.$pages['$action']);
}else{
  echo "Page not found...";
}

Link to comment
https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245794
Share on other sites

In your code you should have something like this:

 

if (isset($_GET['viewpost'])){
   
   //code here for the post viewing

exit; // <-------You need that exit so that the rest of the code below won't show.
}

 

That "exit;" line will keep the rest of the code from below that code from showing. Just make sure you have that code above the code that will display when they go to just "index.php".

Link to comment
https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245819
Share on other sites

u meant put the action=index pagesource in index.php, right?

 

Right, but that is the same script. The only difference is that code would be at the bottom of the script and not in between an IF statement. So that shouldn't create a mess at all.

 

Shaun - Your welcome =] I assume it is working now?

Link to comment
https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245822
Share on other sites

u meant put the action=index pagesource in index.php, right?

 

Right, but that is the same script. The only difference is that code would be at the bottom of the script and not in between an IF statement. So that shouldn't create a mess at all.

 

Shaun - Your welcome =] I assume it is working now?

 

i suppose, i personally like to keep my page code outside the controller, sort of a half-arsed mvc mentality

 

plus whenever your loading other pages, you would have the overhead of that index code

Link to comment
https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245827
Share on other sites

No, you don't have overhead of the index code...all you have to do is exit out of all your other code so that everything below it is ignored, which would be the index code...so it wouldn't show. Although I can see both the pros and cons of it...I am sure there are better methods, but this one works for me.

Link to comment
https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245831
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.