jeff5656 Posted June 4, 2010 Share Posted June 4, 2010 I am about to take the plunge and learn to write some functions to make my coding easier. However, what I can't seem to find in any of the tutorials is *where* do I store these functions and when do I run them? DO I have a file called functions.php and then put an include line in every single php page I have? I that was the case, it would kind of negate the advantgae of having a function - so I think I am not "getting" something. I figured I would just ask the experts :-) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 4, 2010 Share Posted June 4, 2010 Yes, that's what you do. Why do you think that negates anything? Ken Quote Link to comment Share on other sites More sharing options...
ignace Posted June 4, 2010 Share Posted June 4, 2010 DO I have a file called functions.php and then put an include line in every single php page I have? You can create a file that will act as your "hey, start my application god damit!" (commonly referred to as bootstrap) commonly they use the index.php as it's called by default by your server. This could look like: $page = basename($_GET['page']); include('library/functions.php'); switch ($page) { case 'home': include('pages/home.php'); break; .. } I do not advice you would put all your functions in one file though. As your application grows, more functions are added and this can cause an over-head especially for those pages that only use 1 or 2 functions. Over time this will grow to something like: require_once('libraries/somelibrary/frontcontroller.php'); FrontController::start($_REQUEST); And this would load an acronym like MVC where the M toys with a DBAL and they all live in Abstract-ville Quote Link to comment 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.