TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble 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
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-09-2008, 12:35 AM   #1 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default 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:
<?php
require('Smarty.class.php');

$smarty = new Smarty;

$smarty->template_dir "templates";
$smarty->config_dir "config";
$smarty->cache_dir "cache";
$smarty->compile_dir "compile";
?>
index.php:
PHP Code:
<?php require_once('smarty/smartlibs.php'); 
$smarty->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.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-09-2008, 02:49 AM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Old 04-09-2008, 10:30 AM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

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).
__________________
Tanax is offline  
Reply With Quote
Old 04-09-2008, 10:30 PM   #4 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

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.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-10-2008, 06:23 PM   #5 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

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.
xenon is offline  
Reply With Quote
Old 04-11-2008, 01:17 AM   #6 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Whats a bootstrap file?
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 04-11-2008, 05:03 AM   #7 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Quote:
Originally Posted by Aaron View Post
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.
xenon is offline  
Reply With Quote
Reply



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

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:16 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design