Page 1 of 1

include() problem

Posted: Sun Jun 07, 2009 8:38 am
by PatelNehal
- Domain
-- Helper
---- DomOrder.class.php (class DomOrder)
-- View
---- Domain Registration
------ RegisterDomain.php (HTML + PHP code for user)
-- Controller
---- DomainRegistration.php (class DomainRegistration)


I have a tree structure of folder just like this in my project. Now i am making the object of 'DomainRegistration' class object in RegisterDomain.php, but DomainRegistration.php class is including the 'DomOrder' class from Helper folder.

In DomainRegistration.php i have written

Code: Select all

include('../Helper/DomOrder.class.php')
In RegisterDomain.php i have written

Code: Select all

include('../../Controller/DomainRegistration.php')
when i run the RegistrationDomain.php it is giving me error that it cannot find the file ../Helper/DomOrder.class.php in DomainRegistration.php file.

Please anyone can help me...???

Re: include() problem

Posted: Sun Jun 07, 2009 9:31 am
by Weirdan
PHP Manual wrote: If filename begins with ./ or ../, it is looked for only in the current working directory or parent of the current working directory, respectively.
So to make the include work regardless of where the script containing it was included from you need to use absolute path (calculated dynamically):

Code: Select all

 
include dirname(__FILE__) . '/../Helper/DomOrder.class.php';
 

Re: include() problem

Posted: Sun Jun 07, 2009 3:39 pm
by PatelNehal
I tried this and its working thankx :D

Code: Select all

 
include_once(str_replace("//","/",dirname(__FILE__).'/') .'../Helper/DomOrder.class.php');