I haven’t found exactly what I am after here so bear with me …
On this site - http://www.rkba-2a.com/ - I recently experimented and modified it to use includes to speed up site wide changes - menu in particular. I initially put my include files on root to start with and made up an ''index include" version file set then a ''basefile include" file set, to handle path levels from the one index page to the basefile set of several.
In index.php I called, for example - <?php include(‘sidebar-include-index.php’)?>
In a basefile I called for example - <?php include(‘…/sidebar-include-base.php’)?>
This works OK, but as a next stage trial placed my basefile includes in the basefile folder. This in theory meant the relative calls would be direct, for example <?php include(‘sidebar-include-base.php’)?>
However … error time … (PHP Warning: include() [<a href=‘function.include’>function.include</a>]: Failed opening ‘sidebar-include-base.php’ for inclusion (include_path=‘.:/usr/lib64/php:/usr/lib/php’) in /home7/thingame/public_html/rkba-2a.com/basefile/acc-death-stats.php on line 20)
Now, this site is a sub domain and so it seems when trying a simple relative link include in a sub folder - php is wanting a full php include path. But of course all seems fine if includes called from root.
I develop pages under Wamp - which of course has a different include path … <?php echo $_SERVER[‘DOCUMENT_ROOT’] ?> brings up I:/Wamp-server/wamp/www/ but on the web server I get of course - /home7/thingame/public_html/rkba-2a.com
I want flexibility and compatibility with web and my Wamp server so don’t want to try employing full paths just for the web server. Thing is under Wamp my relative include calls work fine but on the server no go - it’s wanting a better path.
Any answer to this so I can work both on Wamp and web server? How come the current set up calling all includes from site root works OK, but trying to use direct relative calls one level down fails (miserably!). Is this just a problem of running a sub domain, relative to the php source? Sorry to be so verbose!!
Totally agreed, I try to keep the dev and production applications identical, otherwise its a total pain in the ass.
Great news! I know you’ll be able to get a solution working. Config files are always a pain to work with, but once that’s set it’ll vastly simplify your deployment process. I remember spending a week to learn all the ins and outs of setting up and using MySQL with my .NET app. I hated every minute of it, but from the moment it was finished, I knew it would be totally worth it. Someone may have more info and post if you have any specific questions, but I’d wager you’ll be able to figure it out with a google search and a little pain and suffering. As soon as it’s over, it’ll be totally worth it.
Update - chatted with host and seems I may have to work out a fix involving the PHP.ini file and maybe too an .htaccess - neither of which I am totally skilled on. The PHP.ini is I am told now set to effectively include all subs as well as main domain … guess I’ll have to do some reading up here.
But if anyone experienced in this can offer any input it’d be most appreciated.
Yes, dev works great - it is indeed the web server angle that presents the problems, and ideally I want to be able to have developed pages behave when uploaded. I think I will contact my host and just see what they say. Thanks.
Good question. I’m not sure about the implementation so I really hope someone can help with the problem.
From an information architecture standpoint, you definitely want to do anything you can to condense code into one place. DRY code (“Don’t Repeat Yourself”) is so much easier to read AND MAINTAIN that WET code (“Write Everything Twice”). You get the speed of updating that you like as well as being able to affect application wide changes from one place in one file.
Just had one thought. If I read this correctly, everything is working fine in development, but not on the production server. Have you tried contacting the hosting company? I think that chances are that it’s not the issue, but if it is, you could spend a lot of time spinning your wheels until you ask. So that’s the first thing I’d try. They typically won’t answer programming questions at my host, but if you tell them something like “Hi, I have code that’s working fine on my development box, but when I upload it to your server, it throws this error (blahblahblah…) I just wanted to see if my account was configured correctly or if this isn’t supposed to work?” As long as you make it clear you respect that they’re not going to give programming advice, my tech support guys are remarkably helpful.