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? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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); Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 4, 2011 Author Share Posted January 4, 2011 Okay, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.