zeusthegreat Posted May 6, 2011 Report Share Posted May 6, 2011 index .php <?php define('APPLICATION_PATH', realpath('../')); $paths = array( APPLICATION_PATH, APPLICATION_PATH . '/com', get_include_path() ); set_include_path(implode(PATH_SEPARATOR, $paths)); function _autoload($className) { $filename =str_replace('\\', '/' ,$className) . '.php'; require_once $filename; } //use \com\killerphp\models as models; $User = new \com\killerphp\models\User(); echo $User->getName(); User.php (this being the class page) <?php namespace com\killerphp\models; class User { public function getName() { return "John smith"; } } ?> returns from browser Fatal error: Class 'com\killerphp\models\User' not found in C:\wamp\www\killerphp\public\index.php on line 21 this is probably something really easy i hope!!! Quote Link to comment Share on other sites More sharing options...
falkencreative Posted May 6, 2011 Report Share Posted May 6, 2011 Didn't you already ask this question? You need to use two underscores within the autoload line: function __autoload($className) Quote Link to comment Share on other sites More sharing options...
zeusthegreat Posted May 6, 2011 Author Report Share Posted May 6, 2011 done that sorry and i return the below error Warning: require_once(com/killerphp/models/User.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\killerphp\public\video2\video3\index.php on line 15 Fatal error: require_once() [function.require]: Failed opening required 'com/killerphp/models/User.php' (include_path='C:\wamp\www\killerphp\public\video2;C:\wamp\www\killerphp\public\video2/com;.;C:\php5\pear') in C:\wamp\www\killerphp\public\video2\video3\index.php on line 15 Quote Link to comment Share on other sites More sharing options...
falkencreative Posted May 6, 2011 Report Share Posted May 6, 2011 That error indicates that it can't find the file within the com/killerphp/models/ folders. Do you have that set up correctly? Is there a "User.php" file within that "models" folder? Also (this may have nothing to do with the error) I noticed that you have the "video3" folder within the "video2" folder. I'm assuming that's done purposely? Just thought I would mention it in case that is causing a path issue. C:\wamp\www\killerphp\public\video2\video3\index.php Quote Link to comment Share on other sites More sharing options...
zeusthegreat Posted May 9, 2011 Author Report Share Posted May 9, 2011 (edited) i have a folder called killerphp in this folder is a folder called public also in the killerphp folder is a folder called com in the public folder is a file called index.php <?php define('APPLICATION_PATH', realpath('../')); $paths = array( APPLICATION_PATH, get_include_path() ); set_include_path(implode(PATH_SEPARATOR, $paths)); function __autoload($className) { $filename = str_replace('\\', '/', $className) . '.php'; require_once $filename; return; } //use \com\killerphp\models as models; //var_dump(get_include_path()); //require_once ('user.php'); $User = new \com\killerphp\models\User(); echo $User->getName(); ?> in the folder called com i have a folder called killerphp and in the folder called killerphp i have a folder called models and in the folder called models i have a file called user.php <?php namespace com\killerphp\models; class User { public function getName() { return "John smith"; } } ?> am i doing it wrong placing the killerphp folder inside the com folder Edited May 9, 2011 by talos Quote Link to comment Share on other sites More sharing options...
zeusthegreat Posted May 9, 2011 Author Report Share Posted May 9, 2011 sussed it what a bifo i am sometimes!!!! thanks anyway 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.
Note: Your post will require moderator approval before it will be visible.