Latest Articles
 by awuehr on 11-10-2008 in Tips & Tricks by Village Idiot on 11-04-2008 in Classes & Objects by codefreek on 10-23-2008 in Basic by wiifanatic on 09-12-2008 in Security & Permissions by drewbee on 07-03-2008 in Tips & Tricks
 IRC Channel
 Join the friendly bunch on IRC... (#TalkPHP on Freenode) ...Also available via a web interface. See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
 Associates
 Associates
 TalkPHP » Includes are driving me nuts!!!
 04-09-2008, 12:35 AM #1 (permalink) The Frequenter   Join Date: Dec 2007 Location: In my basement Posts: 386 Thanks: 47 Includes are driving me nuts!!! Im going to go insane figuring out a way to make these include files work. I finally get one directory to work, and then another one goes and doesn't work. How do you guys work on your local machine?! Paths need to be relative to be able to transfer from one machine to another, and relative paths SUCK! Aside from include problems, where I can rest in peace by just adding a "../" for every directory I go down (it would be great if I didn't have to), I need to deal with these smarty problems. smarty_libs.php: PHP Code:  template_dir = "templates"; $smarty->config_dir = "config";$smarty->cache_dir = "cache"; $smarty->compile_dir = "compile"; ?>  index.php: PHP Code:  assign("location","here");$smarty->display("index.tpl"); ?>  File hierarchy: ------------------ index.php /include /smarty /templates /cache /config /compile smarty.class.php smarty_libs.php ------------------- Can somebody stop the headaches? I go down a directory and everything breaks. I can't do absolute paths from the root directory either. __________________ Signatures are nothing but incriminating.
 04-09-2008, 02:49 AM #2 (permalink) is cute and cuddly     Join Date: Mar 2008 Location: Vegas, Baby Posts: 963 Thanks: 31 I wish I could remember who it was who suggest this, so I could give them credit, but have you tried using $_SERVER['DOCUMENT_ROOT']? I've started to employ this between my test machine and my remote server and it works quite well. Say if you're local is a windows box, and the document root is C:\my documents\htdocs, and your remote is linux, and it's /www/public_html, using document root, you never have to worry about relative paths, you just include($_SERVER['DOCUMENT_ROOT'] . "/path/to/include.php"); It's just like using include("C:\my documents\htdocs\path\to\include.php"); or include("/www/public_html/path/to/include.php"); except that since you're calling the _SERVER array it will automagically fill in the root based on whatever machine you may transfer the script to. -m
 04-09-2008, 10:30 AM #3 (permalink) The Prestige        Join Date: Sep 2007 Location: Sweden, Stockholm Posts: 1,080 Thanks: 115 This is the problem: PHP Code:  $smarty->template_dir = "templates";$smarty->config_dir = "config";$smarty->cache_dir = "cache";$smarty->compile_dir = "compile";   You need to do like: PHP Code:  $smarty->template_dir = "c:/path/to/server/www/projectfolder/templates";$smarty->config_dir = "c:/path/to/server/www/projectfolder/config";$smarty->cache_dir = "c:/path/to/server/somewhereoutside_www/cache";$smarty->compile_dir = "c:/path/to/server/somewhereoutside_www/compile";   The compile and cache isn't supposed to be in the www directory. And also, you need to change php.ini and include that dir.. If you need more detailed description, you could add me to MSN(PM me for my msn). __________________
 04-09-2008, 10:30 PM #4 (permalink) The Frequenter   Join Date: Dec 2007 Location: In my basement Posts: 386 Thanks: 47 I figured out a nicer way from delayedinsanity's. PHP Code:  $install_dir = "Projects/";set_include_path($_SERVER['DOCUMENT_ROOT'] . $install_dir);//@include("anything")  Can some of you crazy "I've been doing PHP since age 3" people on this forum give some suggestions? Edit: DONT USE THIS! :( It screws up any frameworks you might be using. __________________ Signatures are nothing but incriminating.  04-10-2008, 06:23 PM #5 (permalink) The Frequenter Join Date: Dec 2007 Location: Bucharest, Romania Posts: 438 Thanks: 3 Here's a suggestion: in index.php (or what ever your bootstrap file is): Code: define( 'ROOT_DIR', dirname(__FILE__)); then, just use that constant: Code: require_once ROOT_DIR . '/abcd/lib.php'; If you don't use a bootstrap file, then you will have problems, and then you'd better do something like: Code: define('ROOT_DIR',$_SERVER['DOCUMENT_ROOT'] . 'your_app_dir'); Go figure which way works better for you and stick to that. __________________ I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
 04-11-2008, 01:17 AM #6 (permalink) The Frequenter   Join Date: Dec 2007 Location: In my basement Posts: 386 Thanks: 47 Whats a bootstrap file? __________________ Signatures are nothing but incriminating.
The Frequenter

Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3

Quote:
 Originally Posted by Aaron Whats a bootstrap file?
The main file of your application that performs basic initialization and handles requests from users. If you were used to write centralized, extensible applications, you would use a bootstrap to ease your work. A bootstrap example: various frameworks index.php file (Cake, CI, Zend, etc.).

Bootstrapping (computing) - Wikipedia, the free encyclopedia
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)