Jump to content

Functions help


NathanLedet

Recommended Posts

I would like to re-structure a project management site I've been working on.  The way I currently have it is very difficult to follow and not very upgradable.

 

For instance, each action that I take, a new page has to be created. 

 

Example: If i'm on AddressBook.php and I want to add someone to my address book, I have addressbook_add.php or if i want to delete someone, i have addressbook_delete.php.  Each file querys the database and I have a lot of junk everywhere...it's complicated to follow.

 

What I would rather do is use functions in a manner that I've seen used before, where it's something like admin.php?pg=main and for my addressbook I would use somthing like admin.php?pg=addaddress and deleting would be like admin.php?pg=deleteaddress&id=23 where 23 is the ID of the person being removed from the address book.

 

So instead of having numerous pages, I have only admin.php which calls up an external functions file.  Inside that file contains all of my functions which do whatever they need.

 

Where can I start?

Link to comment
https://forums.phpfreaks.com/topic/115503-functions-help/
Share on other sites

Well you need admin.php. Then I would suggest putting the other files in another directory called "pages" or "includes" or something.

Then in your admin.php, where you want the content to appear you would have this:

 

if(!isset($_GET['pg'])){
$pg = "defaultpage";
}else{
$pg = $_GET['page'];
}

if(file_exists("includes/".$pg.".php")){
include("includes/".$pg.".php");
}else{
//They tried to access a page that does not exist
//Include your 404 error page
}

 

Good luck!

Link to comment
https://forums.phpfreaks.com/topic/115503-functions-help/#findComment-593965
Share on other sites

i would try looking at wordpress's code, their create, and edit pages are the same and pretty sweet when you look at the code, its kinda over my head in general and they use all their own functions, but if you look at it for 15 minutes or so you might get some ideas

Link to comment
https://forums.phpfreaks.com/topic/115503-functions-help/#findComment-593996
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.