php - Autoloading Namespaced Classes -
I have searched high and low for an answer and have tried every example, but it is still my classes I fail to find why I'm receiving critical error: class 'project murphys \ model \ database' on C: \ Portables \ xampp \ htdocs \ ProjectMorpheus \ config \ config.php line 23 Not found
Namespace Project Murphys \ Model; Finally, there is a function autoloader function in my config.php (note: __SITE_PATH = 'C: \ Portables \ xampp \ htdocs \ ProjectMorpheus \'):
/ P>
/ *** auto load model class *** / function __autoload ($ square) {$ parts = explosion ('\\', $ class); __SITE_PATH Include 'Model /'. End ($ parts) '.class.php'; } $ Dbh = \ ProjectMorpheus \ Model \ Database :: getInstance ($ DSN, $ username, $ password);
The spl_autoloader appears to be used, but why? My only guess is that $ square is not equal in both instances. My spl_function looks like this:
spl_autoload_register (function ($ square) {$ parts = explosion ('\\', $ class) ; __SITE_PATH is included. 'Model /'. End ($ parts). '.class.php';});
Why do not you use or PSR-4 Autoloader standards?
They are also ready-to-use autoloader classes, as long as you follow the rules, you will not have any problem and your code will be PSR.
Although I would not recommend, but if you want to urge the use of the above code for self-loading classes (only in the model folder) then try dump that __ What is the value of SITE_PATH 'Model /' End ($ parts) '.class.php';
and check if you can access it. You can also try copying and pasting the path of your file explorer to see if the location is accessible and that file exists in that directory.
P. s. I tried to add it as a comment but I could not be due to less representative. Points (new around here and all).
Comments
Post a Comment