The Little Guy Posted January 4, 2011 Share Posted January 4, 2011 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 https://forums.phpfreaks.com/topic/223334-including-files-that-are-moved-around/ Share on other sites More sharing options...
BLaZuRE Posted January 4, 2011 Share Posted January 4, 2011 Give FRAMEWORK an absolute location instead of a relative location. Also, is this the full warning? Warning: include(../Weblyize.php) the file Weblyize.php is a directory above Music.php or a partial with an explanation? Link to comment https://forums.phpfreaks.com/topic/223334-including-files-that-are-moved-around/#findComment-1154487 Share on other sites More sharing options...
The Little Guy Posted January 4, 2011 Author Share Posted January 4, 2011 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 https://forums.phpfreaks.com/topic/223334-including-files-that-are-moved-around/#findComment-1154497 Share on other sites More sharing options...
trq Posted January 4, 2011 Share Posted January 4, 2011 Failed opening '../Weblyize.php' Does not look absolute. Link to comment https://forums.phpfreaks.com/topic/223334-including-files-that-are-moved-around/#findComment-1154499 Share on other sites More sharing options...
The Little Guy Posted January 4, 2011 Author Share Posted January 4, 2011 What if I moved the framework directory somewhere else? Then the I would have to go into each one of those file and change that to an absolute path. I want to redistribute this framework, So I have no Idea where the user will put it. I want to make it dynamic. Link to comment https://forums.phpfreaks.com/topic/223334-including-files-that-are-moved-around/#findComment-1154503 Share on other sites More sharing options...
trq Posted January 4, 2011 Share Posted January 4, 2011 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 https://forums.phpfreaks.com/topic/223334-including-files-that-are-moved-around/#findComment-1154507 Share on other sites More sharing options...
The Little Guy Posted January 4, 2011 Author Share Posted January 4, 2011 So now I did this: ini_set('include_path', FRAMEWORK); include 'commons/Music.php'; and I do this: include 'Weblyize.php'; Which seems to work. Do you see anything wrong with that, or something that may be bad in the future? Any suggestions on that? Link to comment https://forums.phpfreaks.com/topic/223334-including-files-that-are-moved-around/#findComment-1154513 Share on other sites More sharing options...
trq Posted January 4, 2011 Share Posted January 4, 2011 Yeah, what you have will work but, IMO You really should (at least) look at the PEAR naming convention and using __autoload or spl_autoload to load your classes. Link to comment https://forums.phpfreaks.com/topic/223334-including-files-that-are-moved-around/#findComment-1154516 Share on other sites More sharing options...
trq Posted January 4, 2011 Share Posted January 4, 2011 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 https://forums.phpfreaks.com/topic/223334-including-files-that-are-moved-around/#findComment-1154518 Share on other sites More sharing options...
The Little Guy Posted January 4, 2011 Author Share Posted January 4, 2011 Okay, thanks! Link to comment https://forums.phpfreaks.com/topic/223334-including-files-that-are-moved-around/#findComment-1154627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.