Jump to content

tom_burman

New Members
  • Posts

    4
  • Joined

  • Last visited

tom_burman's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. thankyou very much, ill give it a go! Why am i reinventing another framework? For learning mainly my friend, just trying to get better using PHP etc
  2. Could you give me an example please? i'm pretty lost at the moment! first time using namespaces and PSR. Cheers
  3. Thanks trq, that worked perfectly with my router class and i think i understand where i was going wrong. But i now have another issue, as you can see in my file directory i hav a Frontend->Base folders wand within it i have an index and profile folder.There will eventually be alot more folders for differnet parts of the website in here and each folder contains the controller and view for each module of the website. The issue i know have is im not sure on how to autoload the controller classes because the destination folder e.g. frontend->base->index OR frontend->base->profile etc could be different each time. I have called my router like this: $route = new App\Core\router(); $route->setDefaultController(DEFAULT_CONTROLLER); $route->setDefaultMethod(DEFAULT_METHOD); $route->do_route(); $controller = $route->getController(); $method = $route->getMethod(); $arguments = $route->getArgs(); $controller = new App\Core\Frontend\Base\$controller . 'Controller.php'; As you can see at the bottom i have tried to make the correct controler but i cant reference a specific namespaced file because it will constantly be changing. Any ideas? Would psr-4 be better for this? or should i have another router within the Base folder or something? thanks
  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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.