binderman Posted July 6, 2009 Share Posted July 6, 2009 Hi Newbie here - I have written a fairly large php script that handles the data management of a large database. I would like to be able to split the php file into smaller more focused scripts that just do the task of one operation - say manage users, another to manage the contractors in the db, another to manage the parts in the db, and so on. How do I get my main/index.php to call another .php file and pass control to that called .php file? I want control to pass to the called .php file and "close" the calling .php file. Hope that makes sense. Binder. Quote Link to comment https://forums.phpfreaks.com/topic/164949-solved-pass-control-to-another-php-file/ Share on other sites More sharing options...
MadTechie Posted July 6, 2009 Share Posted July 6, 2009 do you mean include a file and why do you want to close file that calls it ? What "controls" do you wish to pass ? Quote Link to comment https://forums.phpfreaks.com/topic/164949-solved-pass-control-to-another-php-file/#findComment-869788 Share on other sites More sharing options...
binderman Posted July 6, 2009 Author Share Posted July 6, 2009 Hi madtechie I'm building my system so that once I have the user login and the user has supplied a valid id and password, they will get passed to menu. The user would then make a selection from the menu - say manage items. I'm thinking (and this is coming from a non-web world, I'm an old vba programmer ) the menu .php script should end/close and the manage items .php script should start/open. IE - instead of having one huge .php file that tries to control all the different options and menu choices, break it into smaller .php files that do smaller jobs. Each time a .php files closes it would pass certain info - user name, session id and such to the new opened .php file. Make sense - or am I going about this the wrong way? Is there a better way to break control in a large system down? Binder Quote Link to comment https://forums.phpfreaks.com/topic/164949-solved-pass-control-to-another-php-file/#findComment-869794 Share on other sites More sharing options...
MadTechie Posted July 6, 2009 Share Posted July 6, 2009 okay a simple way to think of if is like actions for example heres my main page (with menu) <a href="?action=home">home</a><br /> <a href="?action=contact">contact</a><br /> <?php switch($_GET['action']) { case "home": include "home.php"; break; case "contact": include "contact.php"; break; } ?> and heres my pages <?php echo "contect page"; ?> <?php echo "home page"; ?> Now thats kinda basic.. you could also create a file with functions ie <?php function getUserList() { //..code return array(); } function getUserDetails($UserID) { //..code return array(); } ?> and include that into another file to use the functions Quote Link to comment https://forums.phpfreaks.com/topic/164949-solved-pass-control-to-another-php-file/#findComment-869805 Share on other sites More sharing options...
binderman Posted July 6, 2009 Author Share Posted July 6, 2009 That helps a lot thanks. So when a .php is included, the main script is still running? Correct? What does the header("Location: xxx") command do and how is it different from an include? Sorry to be a pest - thanks in advance for your time. Binder. Quote Link to comment https://forums.phpfreaks.com/topic/164949-solved-pass-control-to-another-php-file/#findComment-869812 Share on other sites More sharing options...
MadTechie Posted July 6, 2009 Share Posted July 6, 2009 That helps a lot thanks. So when a .php is included, the main script is still running? Correct? correct, its like you copied and pasted that code into that place, but if you create function you can call them when needed, breaking your large script into smaller functions should help.. then you could put all the database functions into database.php and all the display functions into display.php, once you get used to that then Look at OOP What does the header("Location: xxx") command do and how is it different from an include? Sorry to be a pest - thanks in advance for your time. Binder. Okay header() controls the Page header (who would of guessed) the Location: prefix tell the browser to goto another page. its basically a redirect.. but unlike javascript or metatags you can't have anything displayed on the page Quote Link to comment https://forums.phpfreaks.com/topic/164949-solved-pass-control-to-another-php-file/#findComment-869826 Share on other sites More sharing options...
binderman Posted July 6, 2009 Author Share Posted July 6, 2009 Thanks! I think I understand much better now and will go and try out some code and see my results. I very much appreciate your help. I had been looking at OOP php but figured I'd tackle php from a procedural viewpoint as that's my background. I'll give that a shot soon. Thanks again Binder. Quote Link to comment https://forums.phpfreaks.com/topic/164949-solved-pass-control-to-another-php-file/#findComment-869827 Share on other sites More sharing options...
MadTechie Posted July 6, 2009 Share Posted July 6, 2009 OOP is the better route but most start with procedural, breaking down the code into resuable functions it always a good start Quote Link to comment https://forums.phpfreaks.com/topic/164949-solved-pass-control-to-another-php-file/#findComment-869834 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.