Jump to content

including files that are moved around


The Little Guy

Recommended Posts

I am making a framework for my site, and I have a folder which defines some things. One thing it defines is the location of the frame work:

define('FRAMEWORK', '../../../framework');

 

Next I include a specific class that I include:

include FRAMEWORK.'/commons/Music.php';

 

This class extends the main framework

include '../Weblyize.php';
class Music extends Weblyize{
// Some code
}

 

This issue I am currently having is Warning: include(../Weblyize.php) the file Weblyize.php is a directory above Music.php

 

So, here is where the webpage is located:

http://96.42.108.211:3333/templates/music/music1/about.php

 

Here is where the two classes are located (sub classes are in commons)

http://96.42.108.211:3333/framework/Weblyize.php

http://96.42.108.211:3333/framework/commons/Music.php

 

What is a good way to link the files together with out this breaking no matter where the framework directory is located?

Link to comment
Share on other sites

Here is the error when using absolute:

Warning: include(../Weblyize.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\framework\commons\Music.php on line 2

 

Warning: include() [function.include]: Failed opening '../Weblyize.php' for inclusion (include_path='.;C:\php5\pear') in C:\wamp\www\framework\commons\Music.php on line 2

 

Fatal error: Class 'Weblyize' not found in C:\wamp\www\framework\commons\Music.php on line 3

Link to comment
Share on other sites

I want to redistribute this framework, So I have no Idea where the user will put it. I want to make it dynamic.

 

Every framework that I have ever used simply gets put where ever you like, then the directory containing all the classes is added to php's inlcude_path.

 

You should take a look at how frameworks such as Zend go about it, even PEAR works the same way.

Link to comment
Share on other sites

Actually, doing what you have done will also break the current include_path, meaning that things like PEAR will no longer work. Make sure you always add to the include_path, don't just override it.

 

set_include_path(get_include_path() . PATH_SEPARATOR . FRAMEWORK);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.