Search the Community
Showing results for tags 'psr-0'.
-
I'm beginning to study Composer and am developing a system where I separate the files core application files, as follows: /root |-- /src |-- /App |-- /DBConfig |-- /Controller |-- /Model |-- /Core |-- /Helper |-- /Controller |-- /Model So, to set this setting in composer.json file and get access to all classes both /App much /Core would be this way? "autoload" : { "psr-X" : { "App\\" : "/src", "Core\\" : "/src" } } Or is there a more correct way? I have also read about PSR-0 vs PSR-4 and I am still somewhat in doubt which one to use. In my case what should I implement, PSR-0 or PSR-4?
-
Im trying to implement the PSR-0 autoloader found here : Autoloader I have simply copied and pasted the code as it is shown in the link so should work out of the box. Here is my file structure for my App: I believe i have set up the file structure correctly. App being the vendor, and then the folders below all being namespaces e.g. Frontend, Base, index will all be namespaces and subnamespaces. The autoloader classes specifies this code in order the initiate the autoloader: $classLoader = new SplClassLoader('Doctrine\Common', '/path/to/doctrine'); $classLoader->register(); And in my app i have used this: $classLoader = new SplClassLoader('App', SITE_ROOT); $classLoader->register(); The reason i have only put App as the namespace for the classLoader function is because i need to autoload all classes under the App folder. Here is the initiation of my router class which i believe should be autoloaded so i don't have to include it: $route = new router(); $route->setDefaultController(DEFAULT_CONTROLLER); $route->setDefaultMethod(DEFAULT_METHOD); $route->do_route(); $controller = $route->getController(); $method = $route->getMethod(); $arguments = $route->getArgs(); Is this correct? it doesnt seem to be loading any of the classes, not even the router class which is in the same directory as the autoloader? Im getting pretty confused about what should be parsed to the SPLClassLoader function shown above for a namespace. Any help in this area will be much appreciated Thanks
- 6 replies
-
- mvc
- autoloading
-
(and 2 more)
Tagged with: