include() problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PatelNehal
Forum Newbie
Posts: 21
Joined: Mon Mar 23, 2009 7:27 am
Location: Gujarat, India

include() problem

Post 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...???
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: include() problem

Post 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';
 
User avatar
PatelNehal
Forum Newbie
Posts: 21
Joined: Mon Mar 23, 2009 7:27 am
Location: Gujarat, India

Re: include() problem

Post by PatelNehal »

I tried this and its working thankx :D

Code: Select all

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