Global namespace alias declaration
Posted: Tue Aug 23, 2011 11:33 am
I'm starting to get into the new namespace stuff in 5.3; it's making organizing my MVC stuff a lot easier. One issue I'm having is keeping a namespace alias declaration across different classes. For instance, on my index page, I have
...and then within a class in, say, the "system" namespace, at /application/system, I want to instantiate an object in the auth namespace. Ideally I'd like to be able to say something like:
...but if I do that then it searches for the relative path /Auth/AuthAdmin.php within the /application/system/ folder. I.E., it tries to include /application/system/Auth/AuthAdmin.php, but obviously can't find it.
This problem likely has to do with how my __autoload function is set up:
But here I'm just making use of the aliases I declared above to easily include the necessary class files. Like I said, this works fine outside of a class scope, but inside of a class with a declared namespace at the top, the aliases are either not being used, or they're being used within the class' namespace.
Odds are I just don't entirely understand how this whole system works, but if someone could point me in the right direction I'd appreciate it.
Thanks!
Code: Select all
use \application\auth as Auth;Code: Select all
$this->Authorizer = new Auth\AuthAdmin;This problem likely has to do with how my __autoload function is set up:
Code: Select all
function __autoload($class) {
$filename = str_replace('\\', '/', $class) . '.php';
require_once ($filename);
}Odds are I just don't entirely understand how this whole system works, but if someone could point me in the right direction I'd appreciate it.
Thanks!